6
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Introduction to Data Management Lecture #3 E-R Model, Continued Instructor: Mike Carey [email protected] Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 2 It’s time for.... Brought to you by

Introduction to Data Management Lecture #3 E-R Model

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Introduction to Data Management

Lecture #3E-R Model, Continued

Instructor: Mike Carey [email protected]

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 2

It’s time for....

Brought to you by

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 3

Today’s Reminders

v Read (and live by!) the course wiki page:§ http://www.ics.uci.edu/~cs122a/

v Also follow (and live by) the Piazza page:§ https://piazza.com/uci/spring2018/cs122a/home§ Everyone needs to get signed up! (~ ½ way there)

v The first HW assignment is now available!§ Conceptual database design for our next-generation, cloud-

based replacement for Piazza and EEE à PEEEza (J)v And last but not least…

§ We finally landed a well-qualified Reader #3, so we may be able to open the door a bit for the discussions (upping the cap to 70 students à 420 total) if we can secure a bigger lecture hall…

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 4

More on Assignment 1

v Due date : April 13th 5PM (Friday the 13th J)v Late submission : April 14th 5PM with 20%

point deductionv Use software to draw your E-R diagram in the

provided template and follow the instructions carefully

v Submit your assignment to Gradescopev Everyone should have received Gradescope

(if not, join using the following code: 9ZR22G)

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 5

Another Example (Review)

rankname dname

dno main_office

In DeptProfessor

fac_id

Head

M N

1 NAssigned

Parking Space

pidlot_num

space_num

1

1

(Note that we’re using M:N notation, not ‘s, here.)

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 6

Another Example (E’s & R’s)

nu

n

nu

n

n

n

n

u

u

u

u

u

n

n

n

S1

S2

S3

P1

P2

P3

P4

D1

D2

D3

u

u

u

ParkingSpaces Assigned

(1:1)

Professors

In(M:N)

Head(1:N)

Departments

nu

Entity instance

Relationship instance

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 7

Weak Entitiesv A weak entity can be identified uniquely only by

considering the primary key of some other (owner) entity.§ Owner entity set and weak entity set must participate in a one-to-

many relationship set (one owner, many weak entities).§ Weak entity set must have total participation in this identifying

relationship set. § Dependent identifier is unique only within owner context ( ),

so its fully qualified key here is (ssn, dname)

lot

nameagedname

DependentsEmployees

ssn

Policy

premium

1 N

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 8

Ternary Relationships (and beyond)

namedocid

DoctorPrescribe

name

Patient

ssn phone

Drug

drugcode name descrip

specialty

school

M

N

1

v A prescription is a 3-way relationship between a patient, a doctor, and a drug; with the cardinality constraints above:§ A given patient+drug will be associated with one doctor (1)§ A given patient+doctor may be associated with several drugs (N)§ A given doctor+drug may be associated with several patients (M)

v General note: Relationship key ≤ (entity keys)

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 9

ISA (“is a”) Hierarchies

Contract_Emps

namessn

Employees

lot

hourly_wagesISA

Hourly_Emps

contractid

hours_workedv As in Java or other PLs, ER attributes are inherited (including the key attribute).v If we declare A ISA B, every A entity is also considered to be a B entity. v Covering constraints: Must every Employees entity be either an Hourly_Emps

or a Contract_Emps entity? (Yes or no) § Ex: Hourly_Emps AND Contract_Emps COVER Employees (pick 1 of 2 vs. 1 of 3)

v Overlap constraints: Can some Employees entity be an Hourly_Emps as well as a Contract_Emps entity? (Allowed or disallowed)§ Ex: Hourly_Emps OVERLAPS Contract_Emps (else pick 1 of the 3 types)

v Reasons for using ISA: § To add descriptive attributes specific to a subclass.§ To identify subclasses that participate in a relationship.

v Design: specialization (top-down), generalization (bottom-up)

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 10

Aggregation

v Used when we have to model a relationship involving (entitity sets and) a relationship set.§ Aggregation allows us

to treat a relationship set as an entity set for purposes of participating in (other) relationships.

☛ Aggregation vs. ternary relationship: v Monitors is a distinct relationship;

even has its own attribute here.v Each sponsorship can monitored by

zero or more employees (as above).

budgetdidpidstarted_on

pbudgetdname

until

DepartmentsProjects Sponsors

Employees

Monitors

lotname

ssn

since

M N

M

N

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 11

Additional Advanced ER Featuresv Multi-valued (vs. single-valued)

attributes

Employees

phonename

ssn v Derived (vs. base/stored)attributes

Employees

bdatenamessn

age

Employees

namessn address

snum

street

city

zip

v Composite (vs. atomic) attributes

NOTE: Can model (two of) these using additional entity and relationship types in vanilla E-R tools