Model
Model
Book Chapters
(4th) Chapters 1.3-5, 3.1, 4.11
(5th) Chapters 1.3-7, 2.1, 3.1-2, 4.1
(6th) Chapters 1.3-6, 2.105, 3.1-2, 4.5
Things to Learn
Data model
Relational model
Database construction steps
Data Model
The way we model/conceptualize/visualize/represent data
Need some representation to manage data in a computer
Many different ways to model data
Example (Airline flight): Graph model
Node: city
Edge: flight between cities
Label on edge: flight time, etc.
Example (Company hierarchy): Tree model
CEO Presidents Vice presidents Department heads . . .
Many others, like object model, XML model, network model, etc.
Models to learn in the class: Relational and E/R model
Relational Model
Example: Student(sid, name, address, age, GPA)
Student
sid name
addr
age GPA
301 John
183 Westwood
19
2.1
303 Elaine 301 Wilshire
17
3.9
401 James 183 Westwood
17
3.5
208 Esther 421 Wilshire
20
3.1
All data is represented as relations (= tables)
Each relation has a set of attributes (= columns)
Each relation contains of a set of tuples (= rows)
Each attribute has a domain (= type)
Only atomic types
Similar to Excel spreadsheet
Instance (= Data)
Actual contents (tuples) of relation (explain using the table example)
Schema Type, Instance Value
Schema Class, Instance Instance
Keys
A set of attributes that are known to be unique in the relation
Student(sid, name, address, GPA, age)
Course(dept, cnum, sec, unit, instructor, title)
Multiple keys possible
Course(dept, cnum, sec, unit, instructor, title)
Course(dept, cnum, sec, unit, instructor, title)
Course(dept, cnum, sec, unit, instructor, title)
Q: When do we need keys? How can they be used?
Name Scope
Names of relation: Unique across relations
Names of attributes: Unique in a table, same name in different tables OK
Set semantics
No duplicate tuples (different in SQL. More discussion later)
Q: Can a relation with no duplicates have no keys?
Tuple order does not matter
Authors of a paper: Need explicit ordering
Orders of attributes do not matter
3
Null value
Common interpretation
Do not know
Do not want to say
Not applicable
Example: Student(id, dept, name, GPA) before first quarter?
Complications from Null
Example: Student(id, dept, name, age, GPA)
Q1 : Find students whose age 20. Susans age is Null. Susan in the result?
Q2 : Find students whose age < 20. Susan in the result?
Q3 : Find students whose age 20 or age < 20 and. Susan in the result?
But Q3 = Q1 Q2 ? Something is wrong.
Relational algebra, SQL: 3-valued logic
Every condition is evaluated as True, False or Unknown
Various (arbitrary) rules to deal with anomalous situation
More discussion later
Unfortunately, Nulls are very common in DB.
Significant complexity in DBMS implementation
Loading data
Vendor specific
Oracle, MySQL
LOAD DATA INFILE <datafile> INTO TABLE Course
DB2
IMPORT FROM <datafile> OF DEL INSERT INTO Course
Bulk-load from a comma separated file
6
Things to remember
Data model
Schema
Instance
Relational model
relation, attribute, tuple, domain
key
null value
set semantics
Database construction steps
1. Domain analysis
2. Database design: E/R model, database design theory
3. Table creation: DDL
4. Load
5. Query and update: DML