lect2
lect2
Entity/Relationship Model
Describing Data: Data
Models
• Data model : collection of concepts for
describing data.
Physical Schema
• Physical schema describes the
files and indexes used.
DB
Example: University
Database
• Conceptual schema:
– Students(sid text, name text,
login text, age integer,
gpa float)
– Courses(cid text, cname text,
credits integer)
– Enrolled(sid text, cid text,
grade text)
• Physical schema:
– Relations stored as unordered files.
– Index on first column of Students.
• Q: Why particularly
Because important
databases and for
DBMS?their associated
Data Models
• Connect concepts to
bits!
• Many models exist
• We will ground
ourselves in the Student (sid: string, name: string, login:
Relational model string, age: integer, gpa:real)
– clean and common
– generalization of
key/value
• Entity-Relationship 101011
model also handy for 1101
design
– Translates down to
Entity-Relationship Model
• Relational model is a great formalism
– and a clean system framework
• But a bit detailed for design time
– a bit fussy for brainstorming
– hard to communicate to customers
• Requirements Analysis
– user needs; what must database do?
• Conceptual Design
– high level description (often done w/ER model)
• Logical Design
– translate ER into DBMS data model
• Schema Refinement
– consistency, normalization
• Physical Design - indexes, disk layout
• Security Design - who accesses what, and how
Conceptual Design
• What are the entities and relationships?
• What info about E’s & R’s should be in DB?
• What integrity constraints (business rules) hold?
• ER diagram is the “schema”
• Can map an ER diagram into a relational schema.
name
ER Model Basics ssn lot
Employees
• Entity:
– A real-world object described by a set of
attribute values.
ssn lot
Employees
since
dname
super- subor-
did budget visor dinate
Reports_To
Departments Works_In
An employee
can work in Works_In
many since
departments; a
dept can have
many
Inemployees.
contrast, each
dept has at most
one manager,
according to the Many-to- 1-to-1
1-to- Many-
key constraint on Many Many to-1
Manages.
Participation Constraints
• Does every employee work in a department?
• If so: a participation constraint
– participation of Employees in Works_In is total (vs. partial)
– What if every department has an employee working in it?
• Basically means “at least one”
since
name dname
ssn lot did budget
Works_In
or
since
Alternative: Crow’s Foot
Notation
Summary so far
name
cost pname age
ssn lot
• Previous example:
– 2 binary relationships better than 1 ternary
relationship.
VS.
Suppliers
can-supply
Suppliers deals-with
Aggregation Employees
Monitors until
started_on since
dname
pid pbudget did budget
?
Loan_Officer
Employees
Loan_Officer
Employees
An Example:
Customers can have checking and savings accts
Checking ~ Savings (many of the same attributes)
Old Way:
An Example:
Customers can have checking and savings accts
Checking ~ Savings (many of the same attributes)
New Way:
acct_no balance
ISA
interest overdraft
subclasses
Conceptual Design Using the ER
Model
• Like multiple
addresses per
employee! name dname
ssn lot did budget
from Duration to
Converting ER to
Relational
• Fairly analogous structure
• But many simple concepts in ER are
subtle to specify in relations
since
name dname
ssn lot did budget
Translation to
relational model?
since
name dname
ssn lot did budget
Works_In
since
Participation Constraints in SQL
name
cost pname age
ssn lot