54
CS 4604: Introduction to Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational Model---Part 3

CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

CS4604:IntroductiontoDatabaseManagementSystems

B.AdityaPrakashLecture#7:Entity/Relational

Model---Part3

Page 2: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

2

PurposeofE/RModel

§  TheE/Rmodelallowsustosketchthedesignofadatabaseinformally.–  Representdifferenttypesofdataandhowtheyrelatetoeachother

§  Designsaredrawingscalledentity-relationshipdiagrams.§  FairlymechanicalwaystoconvertE/Rdiagramstoreal

implementationslikerelationaldatabasesexist.

Prakash2018 VTCS4604

Page 3: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Recap:RelationalModel

§  Builtaroundasingleconceptformodellingdata:therelationortable.

§  Supportshigh-levelprogramminglanguage(SQL).

§  Hasanelegantmathematicaldesigntheory.§ MostcurrentDBMSarerelational.

Prakash2018 VTCS4604 3

Page 4: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Recap:TheRelation

§  Arelationisatwo-dimensionaltable:–  Relationßàtable.–  Attributeßàcolumnname.–  Tupleßàrow(nottheheaderrow).–  Databaseßàcollectionofrelations.

Prakash2018 VTCS4604 4

Page 5: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Recap:TheSchema

§  Theschemaofarelationisthenameoftherelationfollowedbyaparanthetisedlistofattributes–  CoursesTaken(Student,Course,Grade)

§  Adesigninarelationalmodelconsistsofasetofschemas.–  Suchasetofschemasiscalledarelationaldatabaseschema

Prakash2018 VTCS4604 5

Page 6: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

ConvertingE/RDiagramstoRelationalDesigns

§  EntitySetàRelation– AttributeofEntitySetàAttributeofaRelation

§  Relationshipàrelationwhoseattributesare– Attributeoftherelationshipitself–  Keyattributesoftheconnectedentitysets

§  Severalspecialcases:– Weakentitysets.–  Combiningrelations(especiallyformany-onerelationships)

–  ISArelationshipsandsubclasses

Prakash2018 VTCS4604 6

Page 7: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

ExampleforConversion

Prakash2018 VTCS4604 7

Page 8: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

SchemasforNon-WeakEntitySets

§  Foreachentityset,createarelationwiththesamenameandwiththesamesetofattributes

Students(Name,Address)Professors(Name,Office,Age)Departments(Name)

Prakash2018 VTCS4604 8

Page 9: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

SchemasforWeakEntitySets

§  ForeachweakentitysetW,createarelationwiththesamenamewhoseattributesare:–  AttributesofW–  KeyattributesofotherentitysetsthathelpformthekeyforW

Courses(Number,DepartmentName,CourseName,Classroom,Enrollment)

Prakash2018 VTCS4604 9

Page 10: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

SchemasforNon-SupportingRelationships

§  Foreachrelationship,createarelationwiththesamenamewhoseattributesare–  Attributesoftherelationshipitself.–  Keyattributesoftheconnectedentitysets(eveniftheyareweak)

Prakash2018 VTCS4604 10

Page 11: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

SchemasforNon-SupportingRelationships

Prakash2018 VTCS4604 11

Page 12: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

SchemasforNon-SupportingRelationships

§  Take

Prakash2018 VTCS4604 12

Page 13: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

SchemasforNon-SupportingRelationships

§  Take(StudentName,Address,Number,DepartmentName)§  Teach

Prakash2018 VTCS4604 13

Page 14: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

SchemasforNon-SupportingRelationships

§  Take(StudentName,Address,Number,DepartmentName)§  Teach(ProfessorName,Office,Number,DepartmentName)§  Evaluation

Prakash2018 VTCS4604 14

Page 15: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

SchemasforNon-SupportingRelationships

§  Take(StudentName,Address,Number,DepartmentName)§  Teach(ProfessorName,Office,Number,DepartmentName)§  Evaluation(StudentName,Address,ProfessorName,Office,

Number,DepartmentName,Grade)

Prakash2018 VTCS4604 15

Page 16: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

RolesinRelationships

§  IfanentitysetEappearsk>1timesinarelationshipR(indifferentroles),thekeyattributesforEappearktimesintherelationforR,appropriatelyrenamed

PreReq(RequirerNumber,RequirerDeptName,RequirementNumber,RequirementDeptName)

Prakash2018 VTCS4604 16

Page 17: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

CombiningRelations

§  Considermany-oneTeachrelationshipfromCoursestoProfessors

§  Schemasare:Courses(Number,DepartmentName,CourseName,Classroom,Enrollment)Professors(Name,Office,Age)Teach(Number,DepartmentName,ProfessorName,Office)

Prakash2018 VTCS4604 17

Page 18: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

CombiningRelationsCourses(Number,DepartmentName,CourseName,Classroom,Enrollment)Professors(Name,Office,Age)Teach(Number,DepartmentName,ProfessorName,Office)

§  ThekeyforCoursesuniquelydeterminesallattributesofTeach

§  WecancombinetherelationsforCoursesandTeachintoasinglerelationwhoseattributesare–  AlltheattributesforCourses,–  AnyattributesofTeach,and–  ThekeyattributesofProfessors

Prakash2018 VTCS4604 18

Page 19: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

RulesforCombiningRelations

§  WecancombineintoonerelationQ–  TherelationforanentitysetE–  allmany-to-onerelationshipsR1,R2,…,RkfromEtootherentitysetsE1,E2,…,Ekrespectively

§  TheattributesofQare– AlltheattributesofE– AnyattributesofR1,R2,…,Rk–  ThekeyattributesofE1,E2,…,Ek

§  WhatifRisamany-manyrelationshipfromEtoF?

Prakash2018 VTCS4604 19

Page 20: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

SupportingRelationships

§  SchemaforDepartmentsisDepartments(Name)§  SchemaforCoursesisCourses(Number,DepartmentName,CourseName,Classroom,Enrollment)

§ Whatistheschemaforoffer?

Prakash2018 VTCS4604 20

Page 21: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

SupportingRelationships

§  Whatistheschemaforoffer?– Offer(Name,Number,DepartmentName)–  ButNameandDepartmentNameareidentical,sotheschemaforOfferisOffer(Number,DepartmentName)

–  TheschemaforOfferisasubsetoftheschemafortheweakentityset,sowecandispensewiththerelationforOffer

Prakash2018 VTCS4604 21

Page 22: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

SummaryofWeakEntitySets

§  IfWisaweakentityset,therelationforWhasaschemawhoseattributesare–  allattributesofW–  allattributesofsupportingrelationshipsforW–  foreachsupportingrelationshipforWtoanentitysetE–  thekeyattributesofE

§  ThereisnorelationforanysupportingrelationshipforWPrakash2018 VTCS4604 22

Page 23: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

ISAtoRelational

§  Threeapproaches:– E/Rviewpoint– Object-orientedviewpoint– “Flatten”viewpoint

Prakash2018 VTCS4604 23

Page 24: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

RulesSatisfiedbyanISAHierarchy

§  Thehierarchyhasarootentityset§  Therootentitysethasakeythatidentifieseveryentityrepresentedbythehierarchy

§  Aparticularentitycanhavecomponentsthatbelongtoentitysetsofanysubtreeofthehierarchy,aslongasthatsubtreeincludestheroot

Prakash2018 VTCS4604 24

Page 25: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

ExampleISAhierarchy

Prakash2018 VTCS4604 25

Page 26: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

ISAtoRelationalMethodI:E/RApproach

§  Createarelationforeachentityset§  Theattributesoftherelationforanon-rootentitysetEare–  theattributesformingthekey(obtainedfromtheroot)and

–  anyattributesofEitself§  Anentitywithcomponentsinmultipleentitysetshastuplesinalltherelationscorrespondingtotheseentitysets

§  Donotcreatearelationforanyisarelationship§  CreatearelationforeveryotherrelationshipPrakash2018 VTCS4604 26

Page 27: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Example:ISAtoRelationalMethodI:E/RApproach

Students(ID,Name)Undergraduates(ID,Major)Graduates(ID,Major)Masters(ID,Thesis_title_MS)PhDs(ID,Thesis_title_PhD)UTA_for(ID,CourseNum,

DeptName)GTA_for(ID,CourseNum,

DeptName)

Prakash2018 VTCS4604 27

Page 28: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

ISAtoRelationalMethodII:“Flatten”Approach

§  Createasinglerelationfortheentirehierarchy

§  Attributesare–  thekeyattributesoftherootand–  theattributesofeachentitysetinthehierarchy

§  HandlerelationshipsasbeforeStudents(ID,Name,UGMajor,GMajor,Thesis_title_MS,Thesis_title_PhD).

Prakash2018 VTCS4604 28

Page 29: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

ISAtoRelationalMethodIII:ObjectOrientedApproach

§  Treatentitiesasobjectsbelongingtoasingleclass.§  “Class”==subtreeofthehierarchythatincludestheroot.

§  Enumerateallsubtreesofthehierarchythatcontaintheroot.

§  Foreachsuchsubtree,–  Createarelationthatrepresentsentitiesthathavecomponentsinexactlythatsubtree.

–  Theschemaforthisrelationhasalltheattributesofalltheentitysetsinthatsubtree.

§  Schemaoftherelationforarelationshiphaskeyattributesoftheconnectedentitysets.

Prakash2018 VTCS4604 29

Page 30: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Example:ISAtoRelationalMethodIII:ObjectOrientedApproach

Subtreesare:

Prakash2018 VTCS4604 30

Page 31: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Example:ISAtoRelationalMethodIII:ObjectOrientedApproach

Subtreesare:Students(ID,Name)

Prakash2018 VTCS4604 31

Page 32: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Example:ISAtoRelationalMethodIII:ObjectOrientedApproach

Subtreesare:Students(ID)StudentsUGs(ID,Major)

Prakash2018 VTCS4604 32

Page 33: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Example:ISAtoRelationalMethodIII:ObjectOrientedApproach

Subtreesare:Students(ID)StudentsUGs(ID,Major)StudentGs(ID,Major)

Prakash2018 VTCS4604 33

Page 34: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Example:ISAtoRelationalMethodIII:ObjectOrientedApproach

Subtreesare:Students(ID)StudentsUGs(ID,Major)StudentGs(ID,Major)StudentGsMasters(ID,Major,Thesis_title_MS)

Prakash2018 VTCS4604 34

Page 35: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Example:ISAtoRelationalMethodIII:ObjectOrientedApproach

Subtreesare:Students(ID)StudentsUGs(ID,Major)StudentGs(ID,Major)StudentGsMasters(ID,Major,Thesis_title_MS)StudentsGsPhDs(ID,Major,Thesis_title_PhD)

Prakash2018 VTCS4604 35

Page 36: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Example:ISAtoRelationalMethodIII:ObjectOrientedApproach

Subtreesare:Students(ID)StudentsUGs(ID,Major)StudentGs(ID,Major)StudentGsMasters(ID,Major,Thesis_title_MS)StudentsGsPhDs(ID,Major,Thesis_title_PhD)StudentsUGsGsMasters(ID,UGMajor,GradMajor,Thesis_title_MS)

Prakash2018 VTCS4604 36

Page 37: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Example:ISAtoRelationalMethodIII:ObjectOrientedApproach

Subtreesare:Students(ID)StudentsUGs(ID,Major)StudentGs(ID,Major)StudentGsMasters(ID,Major,Thesis_title_MS)StudentsGsPhDs(ID,Major,Thesis_title_PhD)StudentsUGsGsMasters(ID,UGMajor,GradMajor,Thesis_title_MS)

Prakash2018 VTCS4604 37

Whatothersubtreesexist?

Page 38: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

ComparisonoftheThreeApproaches

§  Answeringqueries–  Itisexpensivetoanswerqueriesinvolvingseveralrelations

– QueriesaboutStudentsingeneral– QueriesaboutaparticularsubclassofStudents

Prakash2018 VTCS4604 38

Page 39: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

ComparisonoftheThreeApproaches

§  Numberofrelationsfornrelationsinthehierarchy– Weliketohaveasmallnumberofrelations– Flatten

•  1– E/R

•  n– OO

•  Canbe2^n

Prakash2018 VTCS4604 39

Page 40: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

ComparisonoftheThreeApproaches

§  Redundancyandspaceusage– Flatten

•  MayhavealargenumberofNULLS

– E/R•  Severaltuplesperentity,butonlykeyattributesarerepeated

– OO•  Onlyonetupleperentity

Prakash2018 VTCS4604 40

Inshort,goodenoughruleofthumb:usetheE/Rstyle

Page 41: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

EXAMPLES

Prakash2018 VTCS4604 41

Page 42: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

E/RExample1:USCongress(Handout2)

§  TheUSCongressisbicameralmeaningthatitiscomposedoftwohouses:theHouseofRepresentativesandtheSenate.EverystatehasexactlytwoSenators(ajuniorandaseniormember),butavariablenumberofRepresentatives(exactlyoneperdistrict).Nosenatorcanrepresentmorethanonestateatatime.Likewise,noRepresentativecanservemorethanonedistrictatatime.Everystatehasavariablenumberofdistricts(dependentonpopulation),buteverystatehasatleastonedistrict(inastatelikeDelawarethedistrictboundariesarethestate'sborders).Districtshavenumbers(e.g.,district1).AgivenCongressperson(SenatororRepresentative)cannotserveinbothhousesatagiventime.Congresspeoplehavenamesande-mailaddresses.EveryCongresspersonisamemberofexactlyonepoliticalparty.ExactlyonememberoftheHouseisdesignatedasSpeakeroftheHouse.Lastly,CongresspeoplebelongtoCongressionalcommitteeswhichhavenamesandsponsorbills,whichalsohavenames."

Prakash2018 VTCS4604 42

Page 43: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Prakash2018 VTCS4604 43

Page 44: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Prakash2018 VTCS4604 44

Page 45: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Prakash2018 VTCS4604 45

Page 46: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Prakash2018 VTCS4604 46

Page 47: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Prakash2018 VTCS4604 47

Page 48: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Prakash2018 VTCS4604 48

Page 49: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Prakash2018 VTCS4604 49

Page 50: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

Prakash2018 VTCS4604 50

Notes:1.  SpeakerisNOTNULL

Page 51: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

E/RExample2:CompanyDB§  A company database needs to store information about

employees (identified by ssn, with salary and phone asa t t r i b u t e s ) , d epa r tmen t s ( i d en t i f i e d b y dno ,with dname and budget as attributes), and children ofemployees (with name and age as attr ibutes) .Employees work in departments; each departmentis managed by an employee; a child must be identifieduniquely by name when the parent (who is an employee;assume that only one parent works for the company) isknown.

Prakash2018 VTCS4604 51

Page 52: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

§  A company database needs to store information about employees(identified by ssn, with salary and phone as attributes), departments(identifiedbydno,withdnameandbudgetasattributes),andchildrenofemployees(withnameandageasattributes).

Note:Childisaweakentity

Prakash2018 VTCS4604 52

Page 53: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

§  Employeesworkindepartments;§  eachdepartmentismanagedbyanemployee;

Prakash2018 VTCS4604 53

Page 54: CS 4604: Introduction to Database Management Systemscourses.cs.vt.edu/~cs4604/Fall18/lectures/lecture-7.pdf · Database Management Systems B. Aditya Prakash Lecture #7: Entity/Relational

§  achildmustbe identifieduniquelybynamewhentheparent (who isanemployee;assumethatonlyoneparentworksforthecompany)isknown.

Prakash2018 VTCS4604 54