Professional Documents
Culture Documents
DR Daniel Soper Database l2
DR Daniel Soper Database l2
Lecture 2
Spring 2017
MW 3:25 pm – 4:40 pm
January 18 – May 3
Dewey 1101
Agenda
4. Multi-table queries
• ACTIVITY: Multi-table queries!
2
Table Schemas
3
Database Schema
vs. Database State
• Database State:
– Refers to the content of a database at a moment in time.
• Initial Database State:
– Refers to the database state when it is initially loaded into the
system.
• Valid State:
– A state that satisfies the structure and constraints of the database.
Slide 2- 4
Database Schema
vs. Database State (continued)
• Distinction
– The database schema changes very infrequently.
– The database state changes every time the database is updated.
Slide 2- 5
Example of a Database Schema
Slide 2- 6
Example of a database state
Slide 2- 7
Three-Schema Architecture
Slide 2- 8
Three-Schema Architecture
Slide 2- 9
The three-schema architecture
Slide 2- 10
Three-Schema Architecture
Slide 2- 11
Data Independence
Slide 2- 12
Data Independence (continued)
Slide 2- 13
DBMS Languages
Slide 2- 14
DBMS Languages
Slide 2- 15
DBMS Languages
Slide 2- 16
Types of DML
Slide 2- 17
DBMS Interfaces
Slide 2- 18
DBMS Programming Language Interfaces
Slide 2- 19
User-Friendly DBMS Interfaces
– Menu-based (Web-based)
• popular for browsing on the web
– Forms-based
• designed for naïve users used to filling in entries on a form
– Graphics-based
• Point and Click, Drag and Drop, etc.
• Specifying a query on a schema diagram
– Natural language
• requests in written English
– Combinations of the above:
• For example, both menus and forms used extensively in Web database
interfaces
Slide 2- 20
Other DBMS Interfaces
Slide 2- 21
Typical DBMS Component Modules
Slide 2- 22
1. SQL INTRODUCTION & DEFINITIONS
23
What you will learn about in this section
1. What is SQL?
24
Basic SQL
25
SQL Introduction
• SQL language
– Considered one of the major reasons for the commercial
success of relational databases
• SQL
– The origin of SQL is relational predicate calculus called
tuple calculus which was proposed initially as the language
SQUARE.
– SQL Actually comes from the word “SEQUEL (Structured English
Query Language)”
• Original term used in the paper: “SEQUEL TO SQUARE” by Chamberlin
and Boyce. IBM could not copyright that term, so they abbreviated to SQL
and copyrighted the term SQL.
– Now popularly known as “Structured Query language”.
Slide 6- 4
SQL Data Definition, Data Types, Standards
• Terminology:
– Table, row, and column used for relational model terms relation,
tuple, and attribute
• CREATE statement
– Main SQL command for data definition
Slide 6- 5
SQL is a…
29
Tables in SQL
A relation or table is a
Product multiset of tuples
PName Price Manufacturer
having the attributes
specified by the
Gizmo $19.99 GizmoWorks
schema
Powergizmo $29.99 GizmoWorks
Let’s break this
SingleTouch $149.99 Canon
definition down
MultiTouch $203.99 Hitachi
30
Tables in SQL
A multiset is an
unordered list (or: a
Product
set with multiple
PName Price Manufacturer duplicate instances
Gizmo $19.99 GizmoWorks allowed)
Powergizmo $29.99 GizmoWorks List: [1, 1, 2, 3]
Set: {1, 2, 3}
SingleTouch $149.99 Canon Multiset: {1, 1, 2, 3}
31
Tables in SQL
32
Tables in SQL
Product
PName Price Manufacturer
Gizmo $19.99 GizmoWorks
33
Tables in SQL
Product
PName Price Manufacturer
Gizmo $19.99 GizmoWorks
The number of tuples
Powergizmo $29.99 GizmoWorks is the cardinality of
the relation
SingleTouch $149.99 Canon
The number of
attributes is the arity
of the relation
34
Data Types in SQL
• Atomic types:
– Characters: CHAR(20), VARCHAR(50)
– Numbers: INT, BIGINT, SMALLINT, FLOAT
– Others: MONEY, DATETIME, …
35
Key constraints
– i.e. if two tuples agree on the values of the key, then they
must be the same tuple!
In SQL, we may constrain a column to be NOT NULL, e.g., “name” in this table
General Constraints
40
Acknowledgement