You are on page 1of 31

EntityRelationship

Entity
RelationshipModels
Models
ZakiMalik
September 23, 2008
September23,2008

Exercise #1
Exercise#1
Auniversitydatabasecontainsinformationaboutprofessors
(id tifi d b
(identifiedbysocialsecuritynumber)andcourses
i l
it
b ) d
(identifiedbycourseid).Professorsteach courses;eachof
thefollowingsituationsconcernstheTeachesrelationship
set.Foreachsituation,drawanERdiagramthatdescribes
it.
Professorscanteachthesamecourseinseveralsemesters,
Professors can teach the same course in several semesters
andeachofferingmustberecorded.

Exercise #2
Exercise#2
Professorscanteachthesamecourseinseveralsemesters,
andonlythemostrecentsuchofferingneedstobe
recorded.

Exercise#3and4
Everyprofessorteachesexactlyonecourse(nomore,no
less)

Everyprofessorteachesexactlyonecourse(nomore,no
less),andeverycoursemustbetaughtbysomeprofessor

Practice

Professors haveanSSN,aname,anage,arank,andaresearchspecialty.
Projects haveaprojectnumber,asponsorname(e.g.,NSF),astartingdate,an
(
)
endingdate,andabudget.

Graduatestudents haveanSSN,aname,anage,andadegreeprogram
Each project is managed byexactlyoneprofessor(knownasPI)
Eachprojectismanaged
by exactly one professor (known as PI)
Eachprojectisworkedin byoneormoreprofessors(knownasCoPIs)
Eachprojectisworkedon byoneormoregraduatestudents(knownasRAs)

Whengraduatestudentsworkon aproject,aprofessormustsupervise theirwork


ontheproject.Graduatestudentscanworkonmultipleprojects,inwhichcase
theywillhaveapotentiallydifferentsupervisorforeachproject.
Departments haveadepartmentnumber,adepartmentname,andamainoffice.
Departmenthasaprofessor(knownasChairman)whoruns thedepartment.

Professorsworkin oneormoredepartments,andforeachdepartmentthatthey
workin,atimepercentage isassociatedwiththeirjob
Graduate students have one major departmentinwhichtheyareworkingontheir
Graduatestudentshaveonemajor
department in which they are working on their
degree.
Eachgraduatestudentmusthaveanother,moresenior graduatestudentasan
advisor.
advisor

Exercise # 5
Exercise#5

A company database needs to store information about employees


(identified by ssn, with salary and phone as attributes), departments
(identified by dno, with dname and budget as attributes), and children of
employees (with name and age as attributes). Employees work in
d
departments;
each
h department
d
is managed
d by
b an employee;
l
a child
h ld must
be identified uniquely by name when the parent (who is an employee;
assume that only one parent works for the company) is known.

Draw an ER diagram that captures this information.

A company database needs to store information about employees


(identified by ssn, with salary and phone as attributes), departments
(id tifi d by
(identified
b dno,
d
with
ith dname
d
and
d budget
b d t as attributes),
tt ib t ) and
d children
hild
off
employees (with name and age as attributes).

Employees work in departments;


each department is managed by an employee;

a child must be identified uniquely by name when the parent (who is an


employee; assume that only one parent works for the company) is known.

Exercise#6

You set up a database company, ArtBase, that builds a product for art
galleries. The core of this product is a database with a schema that captures
all the information that ggalleries need to maintain.
Galleries keep information about artists, their names (which are unique),
birthplaces, age, and style of art. For each piece of artwork, the artist, the
yyear it was made,, its unique
q title,, its type
yp of art ((e.g.,
g, p
painting,
g, lithograph,
g p ,
sculpture, photograph), and its price must be stored. Pieces of artwork are
also classified into groups of various kinds, for example, portraits, still lifes,
works by Picasso, or works of the 19th century; a given piece may belong to
more than one group. Each group is identified by a name (like those just
given) that describes the group. Finally, galleries keep information about
customers. For each customer, galleries keep that persons unique name,
address,
dd
t t l amountt off dollars
total
d ll spentt in
i the
th gallery
ll
(
(very
i
important!),
t t!) and
d the
th
artists and groups of art that the customer tends to like. Draw the ER diagram
for the database

Gallerieskeepinformationaboutartists,theirnames(whichareunique),
birthplaces,age,andstyleofart.
Foreachpieceofartwork,theartist,theyearitwasmade,itsuniquetitle,itstype
F
h i
f t
k th
ti t th
it
d it
i
titl it t
ofart(e.g.,painting,lithograph,sculpture,photograph),anditspricemustbestored.

Piecesofartworkarealsoclassifiedintogroupsofvariouskinds,forexample,
portraits,still lifes,worksbyPicasso,orworksofthe19thcentury;agivenpiecemay
b l
belongtomorethanonegroup.
t
th
Eachgroupisidentifiedbyaname(likethosejustgiven)thatdescribesthegroup.

Finally,gallerieskeepinformationaboutcustomers.Foreachcustomer,galleries
keepthatpersonsuniquename,address,totalamountofdollarsspentinthegallery
(
(veryimportant!),
i
t t!)
andtheartistsandgroupsofartthatthecustomertendstolike

Exercise#7

Notownrecordshasdecidedtostoreinformationonmusicianswho
performontheiralbums(aswellasothercompanydata)inadatabase.
Thecompanyhaschosentohireyouasadatabasedesigner.
EachmusicianthatrecordsatNotownhasanSSN,aname,anaddressanda
phonenumber.Poorlypaidmusiciansoftensharethesameaddress,andno
h
b
l
d
f
h
h
dd
d
addresshasmorethanonephone.
EachinstrumentthatisusedinsongsrecordedatNotownhasaname(e.g.
guitar synthesizer flute) and a musical key (e g C Bflat Eflat)
guitar,synthesizer,flute)andamusicalkey(e.g.,C,Bflat,Eflat).
EachalbumthatisrecordedattheNotownlabelhasatitle,acopyrightdate,a
format(e.g.,CDorMC)andanalbumidentifier.
EachsongrecordedatNotownhasanid,titleandanauthor.
Each song recorded at Notown has an id, title and an author.
Eachmusicianmayplayseveralinstruments,andagiveninstrumentmaybe
playedbyseveralmusicians.
Eachalbumhasanumberofsongsonit,butnosongmayappearonmore
g
g y pp
thanonealbum.
Eachsongisperformedbyoneormoremusicians,andamusicianmay
performanumberofsongs.
Eachalbumhasexactlyonemusicianwhoactsasitsproducer.Aproducermay
produceseveralalbums.

DrawanERdiagramforNotown.

Each musician that records at Notown has an SSN, a name, an address and
a phone number. Poorly paid musicians often share the same address, and
no address
dd
h more than
has
th one phone.
h

EachinstrumentthatisusedinsongsrecordedatNotown hasaname(e.g.
guitar,synthesizer,flute)andamusicalkey(e.g.,C,Bflat,Eflat).

EachsongrecordedatNotown hasanid,titleandanauthor.

Eachmusicianmayplayseveralinstruments,andagiveninstrumentmay
beplayedbyseveralmusicians.

EachalbumthatisrecordedattheNotown labelhasatitle,acopyright
date,aformat(e.g.,CDorMC)andanalbumidentifier.
Eachalbumhasanumberofsongsonit,butnosongmayappearonmore
E h lb
h
b
f
it b t
thanonealbum.

Eachsongisperformedbyoneormoremusicians,andamusicianmay
performanumberofsongs.

Eachalbumhasexactlyonemusicianwhoactsasitsproducer.Aproducer
mayproduceseveralalbums.

TheE/RModeldescribesadatabaseaboutbandsandtheirtours.Atourconsists
ofasequenceofcitiesvisitedbyaband.Weassumethatnocityisvisitedtwice
onasingletour,andononedate,abandcanvisitonlyonecity.Someofthe
entitysetsareweak,andsomeoftherelationshipsaresupportingmanyone
relationships,butalldoublerectanglesanddoublediamondsarenot shown.
Yourtaskistodecidewhichoftheentitysetsareweak,andwhichrelationships
supportthem.Ifthereisachoice,prefertousetheattributesoftheentityset
itselfinthekey,andminimizethenumberofsupportingrelationships.Theremay
bemorethanonereasonableanswer,especiallysince"tour#"canhaveseveral
reasonableinterpretations.Youshouldpickfromthelistbelowtheonethatis
mostreasonable.

Correct Answers
CorrectAnswers
Stopsisweak,supportedbyOn.
p
, pp
y
Toursisweak,supportedbyBy;tour#isuniqueonlyfora
givenband.
Toursisnotweak;tour#isagloballyuniqueID.
Tours is not weak; tour# is a globally unique ID
Cities
Citiesisweak,anditskeyisthecitynameandthenameof
is weak and its key is the city name and the name of
thestateitisIn.

INCORRECTANSWERS(withexplanation)

Stops is weak, supported by both At and On; date is not a key attribute.
Stopsisweak,supportedbybothAtandOn;dateisnotakeyattribute.

Wearetoldthatatourcannotstopattwocitiesonthesamedate.Thus,onceweknow
thedateandthetourthataStoprepresents,wedon'talsoneedtheCitytohaveakey
forStops.SeeSect.2.4(p.54)fortherulesregardingweakentitysets.

Stopsisweak,supportedbybothAtandOn;dateisakeyattribute.
Wearetoldthatatourcannotstopattwocitiesonthesamedate.Thus,onceweknow
thedateandthetourthataStoprepresents,wedon'talsoneedtheCitytohaveakey
for Stops. See Sect. 2.4 (p. 54) for the rules regarding weak entity sets.
forStops.SeeSect.2.4(p.54)fortherulesregardingweakentitysets.

Stopsisweak,supportedbyAt.

Citiesisnotweak.

AdateandacitydoesnotdefineauniqueStop(City/Tourpair).Thereasonisthat
severaltoursmaystopatthesamecityonthesamedate.SeeSect.2.4(p.54)forthe
rulesregardingweakentitysets.
Thecitynamebyitselfdoesnotdetermineauniquecity.Therecanbecitiesofthe
same name in two or more different states e g Portland ME and Portland OR See Sect
samenameintwoormoredifferentstates,e.g.,PortlandMEandPortlandOR.SeeSect.
2.4(p.54)fortherulesregardingweakentitysets.

Bandsisweak,supportedbyBy.

Asupportingrelationshiphastobemany
A
supporting relationship has to be manyone
onefrom
from theentitysetitsupports.Inorder
the entity set it supports. In order
forthisdiagramtomakesense,wehavetoassumethatbandnamesareunique,
becauseBycannothelpdefineabanduniquelyusingtheweakentitysetconstruct.See
Sect.2.4(p.54)fortherulesregardingweakentitysets.

Statesisweak,supportedbyIn.

Stopsisweak,anditskeyisthedateandthenameofthebandmaking
Stops
is weak and its key is the date and the name of the band making
thetourthestoprepresents.

ThereisnomanyonerelationshipdirectlyfromStopstoBands.Thus,anattributeof
BandscanonlycontributetothekeyofStopsifToursisweakandthebandname
constributestothekeyofTours.Butthen,thetour#wouldalsobeinthekeyforStops.
SeeSect.2.4(p.54)fortherulesregardingweakentitysets.

Stopsisweak,anditskeyisthedate,thenameoftheassociatedcity,and
th
theassociatedtour#.
i t dt #

Asupportingrelationshiphastobemanyonefrom theentitysetitsupports.Notealso
thatstatenamesareunique.SeeSect.2.4(p.54)fortherulesregardingweakentity
sets.

Sinceitisambiguouswhethertour#'sareunique,itispossiblethattherearetwobands
thatusethesametournumber,andthesebandsstopinthesamecityonthesamedate.
SeeSect.2.4(p.54)fortherulesregardingweakentitysets.

Toursisweak,supportedbyOnandBy.

Asupportingrelationshiphastobemanyonefrom theentitysetitsupports.Thus,On
couldn'tpossiblysupportTours.SeeSect.2.4(p.54)fortherulesregardingweakentity
sets.
t

You might also like