Upload
arvind-patel
View
215
Download
0
Embed Size (px)
Citation preview
7/25/2019 Ex Defining Constraint
1/7
Examplesof
Defining
Constraints
7/25/2019 Ex Defining Constraint
2/7
An ER diagram for a COURSES Database
A course may or may not usea textbook
A text by definition is a book
that is used in some course A course may not use more
than five books
Instructors teach from two tofour courses
Each course is taught by exactly one instructor
Each textbook is used by one and only one course
Add the relationship ADOPTS between INSTRUCTOR andTEXT
An instructor does not have to adopt a textbook for all courses
An instructor does not adopt more than three textbooks foreach course
7/25/2019 Ex Defining Constraint
3/7
An ER diagram with defined Constraints
A course may or may not usea textbook.
A text by definition is a book
that is used in some course. A course may not use more
than five books.
Instructors teach from two tofour courses.
Each course is taught by exactly one instructor.
Each textbook is used by one and only one course.
Add the relationship ADOPTS between INSTRUCTOR andTEXT.
An instructor does not have to adopt a textbook for all courses.
An instructor does not adopt more than three textbooks foreach course.
7/25/2019 Ex Defining Constraint
4/7
Another Scenario
There are musicians, identified by first and last name,and each plays an instrument.
There are bands, each with a unique band name. Each
band has a style. CDs are identified by their product ids, and each has a
title and publisher.
A musician is a member of one or more bands and aband has one or more musicians. For each musician ina band there is a date the musician joined and a datethe musician left.
A musician appears on one or more CDs.
Each CD is released by a single band, but a band canrelease any number of CDs. A CD is released by a bandon a release date.
7/25/2019 Ex Defining Constraint
5/7
A possible ER diagram
(1,N)Musician Band CD
Member-of
Released
First
Last
Instrument
Bname
Style
Join-date
Release-date
PidTitle
Publisher
(1,N) (0,N) (0,1)
Find at least 5 problems with this ER diagram relativeto the scenario described above.
List them, and show on the diagram how to fix each
problem.
7/25/2019 Ex Defining Constraint
6/7
The five problems with this ER diagram
(1,N)Musician Band CD
Member
-of
Released
First
Last
InstrumentBname
Style
Join-date
Release-date
Pid Title
Publisher
(1,N) (0,N) (0,1)
Instrument should not be part of the key of Musician.
Missing relationship for Musician appearing on CD.
No date of leaving on Member-of relationship.
Every CD is issued by a Band, so the minimum cardinality on theCD end of the relationship should be 1.
Release date should not be an attribute of Band, since a Band canrelease several CDs. It should be an attribute on either the
Released relationship or the CD entity.
7/25/2019 Ex Defining Constraint
7/7
Modified ER diagram
(1,N)
Musician Band CDMember
-ofReleased
First
Last
InstrumentBname
Style
Join-date
Release-date
PidTitle
Publisher
(1,N) (0,N) (1,1)
1
Appears-
on
(1,N)(1,N)
5
2
4
3Leave-date