Professional Documents
Culture Documents
00 Intro
00 Intro
Introduction
Database Design and ER Models
The Relational Model
• Extremely powerful
• SQL allows for more or less arbitrary queries
• support transactions and the associated guarantees
Transactions
• A transaction is a sequence of operations that is treated as
a single logical operation.
• Other examples:
• making a flight reservation
select flight, reserve seat, make payment
• making an online purchase
• Scalability is crucial
• load can increase rapidly and unpredictably
• use large clusters of commodity machines
OS
• Above that is the logical layer. FS
Course Components
• Lectures and weekly sections
• sections: optional but recommended; start next week
• also available by streaming and recorded video
• Five problem sets
• several will involve programming in Java
• all will include written questions
• grad-credit students will complete extra problems
• must be your own work
• see syllabus or website for the collaboration policy
• Midterm exam
• Final exam
Prerequisites
• A good working knowledge of Java
Course Materials
• Lecture notes will be the primary resource.
• Other options:
• Database Management Systems by Ramakrishnan and
Gehrke (McGraw-Hill)
• Database System Concepts by Silberschatz et al.
(McGraw-Hill)
Additional Administrivia
• Instructor: Dave Sullivan
Database Design
• In database design, we determine:
• which pieces of data to include
• how they are related
• how they should be grouped/decomposed
• ER models specify:
• the relevant entities (“things”) in a given domain
• the relationships between them
• Examples:
Attributes
• Associated with entities are attributes that describe them.
• represented as ovals connected to the entity by a line
• double oval = attribute that can have multiple values
Course
exam dates
Person
Candidate Key
• A candidate key is a minimal collection of attributes that is a key.
• minimal = no unnecessary attributes are included
• not the same as minimum
isbn
author_id, title
author_id, isbn
author_id
Primary Key
• We typically choose one of the candidate keys as the primary key.
Course
exam dates
• Example:
credit status
id name
credit status
Person Studies
Course
In
advisor
Person Advises
advisee
A R B
One-to-One Relationships
• In a one-to-one relationship involving A and B: [not from A to B]
• an entity in A can be related to at most one entity in B
• an entity in B can be related to at most one entity in A
A R B
A R B
Another Example
• How can we indicate that each student has at most one
advisor?
advisor
Person Advises
advisee
person studies
in course
Participation Constraints
• Cardinality constraints allow us to specify that each entity
will appear at most once in a given relationship set.
omitting
Person Chairs Department the cardinality
constraints
for now
• Example of a table:
id name address class dob
12345678 Jill Jones Canaday C-54 2011 3/10/85
25252525 Alan Turing Lowell House F-51 2008 2/7/88
33566891 Audrey Chu Pfoho, Moors 212 2009 10/2/86
45678900 Jose Delgado Eliot E-21 2009 7/13/88
66666666 Count Dracula The Dungeon 2007 11/1431
... ... ... ... ...
Null Values
• By default, the domains of most columns include a special value
called null.
• Example:
Student(id, name, address, email, phone)
MeetsIn(name, name)
MeetsIn(course_name, room_name)
• Example:
MeetsIn(course_name, room_name)
Course(name, start_time, end_time)
Room(name, capacity)
Special Case: Many-to-One Relationship Sets (cont.)
• However, if a relationship set is many-to-one, we often:
• eliminate the relation for the relationship set
• capture the relationship set in the relation used for the
entity set on the many side of the relationship
MeetsIn(course_name, room_name)
Course(name, start_time, end_time, room_name)
Room(name, capacity)
Course MeetsIn
name … course_name room_name
cscie50b cscie50b Sci Ctr B
cscie119 cscie119 Sever 213
cscie160 cscie160 Sci Ctr A
cscie268 cscie268 Sci Ctr A
Course
name … room_name
cscie50b Sci Ctr B
cscie119 Sever 213
cscie160 Sci Ctr A
cscie268 Sci Ctr A
Special Case: Many-to-One Relationship Sets (cont.)
• If one or more entities don't participate in the relationship,
there will be null attributes for the fields that capture the
relationship:
Course
name … room_name
cscie50b Sci Ctr B
cscie119 Sever 213
cscie160 Sci Ctr A
cscie268 Sci Ctr A
cscie160 NULL
• Example:
Person
id Student Student(id, …)
credit status
Borrows(person_id, isbn)
Borrows(person_id, isbn)
Chairs(person_id, department_name)
Foreign Keys
• A foreign key is attribute(s) in one relation that take on values
from the primary-key attribute(s) of another relation.
• example: MajorsIn has two foreign keys
MajorsIn
student department
12345678 computer science
12345678 english
... ...
Student Department
id name … name …
12345678 Jill Jones ... computer science ...
25252525 Alan Turing ... english ...
... ... ... ... ...
Student Department
id name … name …
12345678 Jill Jones ... computer science ...
25252525 Alan Turing ... english ...