cs 4604: introduction to database management...
TRANSCRIPT
![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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/1.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/2.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/3.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/4.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/5.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/6.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/7.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/8.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/9.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/10.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/11.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/12.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/13.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/14.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/15.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/16.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/17.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/18.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/19.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/20.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/21.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/22.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/23.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/24.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/25.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/26.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/27.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/28.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/29.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/30.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/31.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/32.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/33.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/34.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/35.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/36.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/37.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/38.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/39.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/40.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/41.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/42.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/43.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/44.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/45.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/46.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/47.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/48.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/49.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/50.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/51.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/52.jpg)
§ 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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/53.jpg)
§ 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](https://reader036.vdocument.in/reader036/viewer/2022063019/5fde7277a5ba0e5c6d450ffb/html5/thumbnails/54.jpg)
§ achildmustbe identifieduniquelybynamewhentheparent (who isanemployee;assumethatonlyoneparentworksforthecompany)isknown.
Prakash2018 VTCS4604 54