Lecture2 ER - Model Jan9 2018
Lecture2 ER - Model Jan9 2018
Lecture2 ER - Model Jan9 2018
Mohammad Hammoud
Today…
Last Session:
Course overview and a brief introduction to databases
Today’s Session:
Introduction to databases and database systems (Continue)
Main steps involved in designing databases
Constructs of the entity relationship (ER) model
Integrity constrains that can be expressed in the ER model
Announcements:
The first Problem Solving Assignment (PS1) will be posted by tonight on
the course webpage. It is due on January 21 by midnight
Thursday, January 11 is the first recitation
A case study on the ER model will be solved together
Outline
A Primer on Databases
Database Design
Students(sid: string, name: string, login: string, dob: string, gpa: real)
DBMS ensures that conflicts do not arise via using a locking protocol
Shared vs. Exclusive locks
Ensuring Atomicity
Transactions can be interrupted before running to completion for a
variety of reasons (e.g., due to a system crash)
SQL Commands
A Primer on Databases
Database Design
ER Model: Constructs and Constraints
Database Design
Requirements Analysis
Users needs
Conceptual Design
A high-level description of the data (e.g., using the ER model)
Logical Design
The conversion of an ER design into a relational database schema
Schema Refinement
Normalization (i.e., restructuring tables to ensure some
desirable properties)
Physical Design
Building indexes and clustering some tables
Security Design
Access controls
Outline
A Primer on Databases
Database Design
Entity set:
A collection of similar entities (e.g., all employees)
All entities in an entity set have the same set of attributes
(until we consider ISA hierarchies, anyway!)
Each entity set has a key
Each attribute has a domain
Tools and An ER Diagram
Attributes
name
“ssn” is the ssn lot
primary key,
hence, underlined
Employees
Relationship and Relationship Sets
Relationship:
Association among two or more entities (e.g., Mohammad
is teaching 15-415)
Described using a set of attributes
Relationship set:
Collection of similar relationships
Same entity set could participate in different relationship
sets, or in different “roles” in the same set
More Tools and ER Diagrams
N M Relationships (‘rel. sets’)
and mapping constraints
P
name
ssn lot
since
name dname
Employees
ssn lot did budget
super- subor-
visor dinate
Employees Works_In Departments
Reports_To
since
name dname
ssn lot did budget
1 1
1 N
1 N
PERSON owns CAR
N M
STUDENT takes SECTION
Cardinalities: Examples
Book’s notation:
PERSON owns CAR
N M
STUDENT takes SECTION
A Working Example
Requirements: Students take courses offered
by instructors; a course may have multiple
sections; one instructor per section
How to start?
Nouns -> entity sets
Verbs -> relationship sets
...
name
STUDENT
ssn
INSTRUCTOR
issn
Primary key =
unique identifier
underline
...
name
STUDENT
c-id
ssn c-name
COURSE
INSTRUCTOR
issn
But: sections of a course (with
different instructors)?
ssn
STUDENT
c-id
COURSE
s-id SECTION
c-id
COURSE
s-id SECTION
Q: how to
issn INSTRUCTOR record that
students take
courses?
ssn
STUDENT
N
c-id
takes
M
COURSE
s-id SECTION
issn INSTRUCTOR
STUDENT
N
c-id
takes
M
s-id SECTION COURSE
N
teaches
1
INSTRUCTOR
STUDENT
N
c-id
takes
M
N 1
s-id SECTION has COURSE
N
teaches
1
INSTRUCTOR
Participation Constraints
Consider again the “Employees” and “Departments” entity sets as well as the
“Manages” relationship set
Should every department have a manager?
If so, this is a participation constraint
Such a constraint entails that every Departments entity must appear in an
instance of the Manages relationship
The participation of Departments in Manages is said to be total (vs. partial)
since
name dname
ssn lot did budget
name
ssn lot
Hourly_Emps Contract_Emps
Overlap and Covering Constraints
Overlap constraints A
Can an entity belong to
both ‘B’ and ‘C’?
Covering constraints
B C
Can an ‘A’ entity belong
to neither ‘B’ nor ‘C’?
Overlap Constraints: Examples
Overlap constraints A
Can John be in Hourly_Emps and
Contract_Emps? Intuitively, no
Employees
Monitors until
started_on since
dname
pid pbudget did budget