




已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
CHAPTER 7 Database Design and the E R Model This chapter introduces the entity relationship model in detail A signifi cant change in the 6th edition is the change in theE Rnotation used in the book There are several alternativeE Rnotations used in the industry Increasingly however theUMLclassdiagramnotationisusedinsteadofthetraditionalE Rnotationused in earlier editions of the book Among the reasons is the wide availability ofUML tools as well as the conciseness of theUMLnotation compared to the notation with separate ovals to represent attributes In keeping with this trend we have changed ourE Rnotation to be more compatible withUML The chapter covers numerous features of the model several of which can be omitted depending on the planned coverage of the course ExtendedE Rfeatures Section7 8 andallsubsequentsectionsmaybeomittedincaseoftimeconstraints in the course without compromising the students understanding of basicE R modeling However we recommend covering specialization Section 7 8 1 at least in some detail since it is widely used in object oriented modeling TheE RmodelitselfandE Rdiagramsareusedofteninthetext Itisimportant thatstudentsbecomecomfortablewiththem TheE Rmodelisanexcellentcontext for the introduction of students to the complexity of database design For a given enterprise there are often a wide variety ofE Rdesigns Although some choices are arbitrary it is often the case that one design is inherently superior to another Several of the exercises illustrate this point The evaluation of the goodness of anE Rdesign requires an understanding of the enterprise being modeled and the applications to be run It is often possible to lead students into a debate of the relative merits of competing designs and thus illustrate by example that understanding the application is often the hardest part of database design Among the points that are worth discussing when coming up with anE R design are 1 Naming of attributes this is a key aspect of a good design One approach to design ensures that no two attributes share a name by accident thus if ID appears as an attribute of person it should not appear as an attribute of 51 52Chapter 7Database Design and the E R Model another relation unless it references the ID of person When natural joins are used in queries this approach avoids accidental equation of attributes to some extent although not always for example students and instructors share attributes ID and name presumably inherited from a generalization person so a query that joins the student and instructor relations would equate the respective attribute names 2 Primary keys one approach to design creates identifi er values for every entity which are internal to the system and not normally made visible to endusers TheseinternalvaluesareoftendeclaredinSQLasautoincrement meaning that whenever a tuple is inserted to the relation a unique value is given to the attribute automatically In contrast the alternative approach which we have used in this book avoids creating artifi cial internal identifi ers and instead uses externally visible attributes as primary key values wherever possible As an example in any university employees and students have externally visible identifi ers These could be used as the primary keys or alternatively the application can create identifi ers that are not externally visible and use them as the value for the primary key As another example the section table which has the combination of course id section id semester year as primary key could instead have a section identifi er that is unique across all sections as primary key with the course id section id semester year as non primary key attributes The difference would be that the relations that refer to section namely teaches and takes would have a single unique section id attribute as a foreign key referring to section and would not need to store course id section id semester and year Considerable emphasis is placed on the construction of tables fromE Rdia grams This serves to build intuition for the discussion of the relational model in the subsequent chapters It also serves to ground abstract concepts of entities and relationships into the more concrete concepts of relations Several other texts places this material along with the relational data model rather than in theE R model chapter Our motivation for placing this material here is help students to appreciate howE Rdata models get used in reality while studying theE Rmodel rather than later on Exercises 7 14Explain the distinctions among the terms primary key candidate key and superkey Answer Asuperkeyisasetofoneormoreattributesthat takencollectively allows us to identify uniquely an entity in the entity set A superkey may contain extraneous attributes If K is a superkey then so is any superset of K A superkey for which no proper subset is also a superkey is called a candidate key It is possible that several distinct sets of attributes could Exercises53 patients ID name insurance doctors ID name specialization test testId testName Date time result test patient dr patient test doctor Figure 7 1E R diagram for a hospital serve as candidate keys The primary key is one of the candidate keys that is chosen by the database designer as the principal means of identifying entities within an entity set 7 15Construct anE Rdiagram for a hospital with a set of patients and a set of medical doctors Associate with each patient a log of the various tests and examinations conducted Answer AnE Rdiagram for the hospital is shown in Figure7 1 Although the diagram meets the specifi cations of the question a real world hospital would have many more requirements such as tracking patient admissions and visits including which doctor sees a patient on each visit recording results of tests in a more structured manner and so on 7 16Construct appropriate relation schemas for each of theE Rdiagrams in Practice Exercises 7 1 to 7 3 Answer a Car insurance tables customer customer id name address car license model owns customer id license no accident report id date place participated license no report id policy policy id covers policy id license no premium payment policy id payment no due date amount received on Note that a more realistic database design would include details of whowasdrivingthecarwhenanaccidenthappened andthedamage amount for each car that participated in the accident 54Chapter 7Database Design and the E R Model b Student Exam tables i Ternary Relationship student student id name dept name tot cred course course id title credits section course id section id semester year exam exam id name place time exam marks student id course id section id semester year exam id marks ii Binary relationship student ID name dept name tot cred course course id title credits section course id section id semester year exam marks student id course id sec id semester year exam id marks c Player Match tables match match id date stadium opponent own score opp score player player id name age season score played match id player id score 7 17Extend theE Rdiagram of Practice Exercise 7 3 to track the same informa tion for all teams in a league Answer See Figure 7 2 Note that we assume a player can play in only one team if a player may switch teams we would have to track for each match which team the player was in which we could do by turning the relationship played into a ternary relationship 7 18Explain the difference between a weak and a strong entity set Answer A strong entity set has a primary key All tuples in the set are distinguishable by that key A weak entity set has no primary key unless attributes of the strong entity set on which it depends are included Tuples in a weak entity set are partitioned according to their relationship with tuplesinastrongentityset Tupleswithineachpartitionaredistinguishable by a discriminator which is a set of attributes 7 19We can convert any weak entity set to a strong entity set by simply adding appropriate attributes Why then do we have weak entity sets Answer We have weak entities for several reasons We want to avoid the data duplication and consequent possible incon sistencies caused by duplicating the key of the strong entity Weak entities refl ect the logical structure of an entity being dependent on another entity Weak entities can be deleted automatically when their strong entity is deleted Exercises55 match match id date stadium player player id name age season score played score team name season stats match team score result player team Figure 7 2E R diagram for all teams statistics Weak entities can be stored physically with their strong entities 7 20ConsidertheE RdiagraminFigure7 29 whichmodelsanonlinebookstore a List the entity sets and their primary keys b Suppose the bookstore adds Blu ray discs and downloadable video toitscollection Thesameitemmaybepresentinoneorbothformats with differing prices Extend theE Rdiagram to model this addition ignoring the effect on shopping baskets c Now extend theE Rdiagram using generalization to model the case where a shopping basket may contain any combination of books Blu ray discs or downloadable video Answer Interpret the second part of the question as the bookstore adds videos which may be in Blu ray disk format or in downloadable format the same video may be present in both formats a Entity sets author name address URL publisher name address phone URL book ISBN title year price customer email name address phone shopping basket basket id warehouse code address phone 56Chapter 7Database Design and the E R Model video video id title price blu ray discs no of discs downloadable video size of video Figure 7 3ER Diagram for Exercise 7 20 b b The ER diagram portion related to videos is shown in Figure 7 3 c TheE Rdiagram shown in Figure 7 4 should be added to theE Rdi agram of Figure 7 29 Entities that are shown already in Figure 7 29 are shown with only their names omitting the attributes The con tains relationship in Figure 7 29 should be replaced by the version in Figure 7 4 All other parts of Figure 7 29 remain unchanged 7 21Design a database for an automobile company to provide to its dealers to assist them in maintaining customer records and dealer inventory and to assist sales staff in ordering cars item ID title price 1 1 1 contains shopping basket blu ray discs no of discs downloadable video size of video book video Figure 7 4ER Diagram for Exercise 7 20 c Exercises57 brand name has vehicles owned by has models model model id name vehicle VIN has available option options options id specification customer customer id name address has dealer dealer dealer id name address has option Figure 7 5ER Diagram for Exercise 7 21 Each vehicle is identifi ed by a vehicle identifi cation number VIN Each individualvehicleis a particular model of a particular brand offeredby the company e g theXFis a model of the car brand Jaguar of Tata Motors Each model can be offered with a variety of options but an individual car may have only some or none of the available options The database needs to store information about models brands and options as well as information about individual dealers customers and cars Your design should include anE Rdiagram a set of relational schemas andalistofconstraints includingprimary keyandforeign keyconstraints Answer TheE RdiagramisshowninFigure7 5 Notethatthehas optionrelationship links a vehicle to an aggregation on the relationship has available option insteadofdirectlytotheentitysetoptions toensurethataparticularvehicle instance cannot get an option that does not correspond to its model The alternative of directly linking to options is acceptable if ensuring the above integrity constraint is not critical Therelationalschema alongwithprimary keyandforeign keyconstraints is shown below 58Chapter 7Database Design and the E R Model brand name model model id name vehicle VIN option option id specifi cation customer customer id name address dealer dealer id name address has models name model id foreign key name references brand foreign key model id references model has vehicles model id VIN foreign key VIN references vehicle foreign key model id references model available options model id option id foreign key option id references option foreign key model id references model has options VIN model id option id foreign key VIN references vehicle foreign key model id option id references available options has dealer VIN dealer id foreign key dealer id references dealer foreign key VIN references vehicle owned by VIN customer id foreign key customer id references customer foreign key VIN references vehicle Exercises59 customer customer id name address place place id city country address has gone through sends packet packet packet id weight receiver packet As an alternative sends has gone through time sent time received place place id city country address sender receiver customer customer id name address packet packet id weight time received time sent Figure 7 6ER Diagram Alternatives for Exercise 7 22 7 22Design a database for a world wide package delivery company e g DHL or FedEX The database must be able to keep track of customers who ship items and customers who receive items some customers may do both Each package must be identifi able and trackable so the database must be able to store the location of the package and its history of locations Locations include trucks planes airports and warehouses Your design should include anE Rdiagram a set of relational schemas andalistofconstraints includingprimary keyandforeign keyconstraints Answer 60Chapter 7Database Design and the E R Model Two alternativeE Rdiagrams are shown in Figure 7 6 The relational schema including primary key and foreign key constraints corresponding to the second alternative is shown below customer customer id name address packet packet id weight place place id city country address sends sender id receiver id packet id time received time sent foreign key sender id references customer foreign key receiver id references customer foreign key packet id references packet has gone through packet id place id foreign key packet id references packet foreign key place id references place 7 23Design a database for an airline The database must keep track of cus tomers and their reservations fl ights and their status seat assignments on individual fl ights and the schedule and routing of future fl ights Your design should include anE Rdiagram a set of relational schemas andalistofconstraints includingprimary keyandforeign keyconstraints Answer TheE Rdiagram is shown in Figure 7 7 We assume that the schedule of a fl ight is fi xed across time although we allow specifi cation of on which days a fl ight is scheduled For a particular instance of a fl ight however we record actual times of departure and arrival In reality schedules change with time so the schedule and routing should be for a particular fl ight for specifi ed dates or for a specifi ed range of dates we ignore this complexity Exercises61 flight flight id runs on days has traveller customer customer id name address flight instance flight inst id capacity date seat no instance of has status station station id name country has schedule arrival date arrival time departure date departure time arrival dayno arrival time departure dayno departure time Figure 7 7ER Diagram for Exercise 7 23 fl ight instance fl ight inst id capacity date customer customer id name address fl ight fl ight id runs on days station station id name country has traveller fl ight inst id customer id seat number foreign key fl ight inst id references fl ight instance foreign key customer id references customer instance of fl ight inst id fl ight id foreign key fl ight inst id references fl ight instance foreign key fl ight id references fl ight 62Chapter 7Database Design and the E R Model has schedule fl ight id station id order arrival dayno arrival time departure dayno departure time foreign key fl ight id references fl ight foreign key station id references station has status fl ight inst id station id arrival date arrival time departure date departure time foreign key fl ight inst id references fl ight instance foreign key station id references station 7 24In Section 7 7 3 we represented a ternary relationship repeated in Fig ure 7 27a using binary relationships as shown in Figure 7 27b Consider the alternative shown in Figure 7 27c Discuss the relative merits of these twoalternativerepresentationsofaternaryrelationshipbybinary relation ships Answer In the model of Figure 7 27b there can be instances where E A B C RA RBand RCcannot correspond to any instance of A B C and R The model of Figure 7 27c will not be able to represent all ternary relation ships Consider the ABC relationship set below ABC 123 427 483 If ABC is broken into three relationships sets AB BC and AC the three will imply that the relation 4 2 3 is a part of ABC 7 25Consider the relation schemas shown in Section 7 6 which were generated fromtheE RdiagraminFigure7 15 Foreachschema specifywhatforeign key constraints if any should be created Answer The foreign key constraints are as specifi ed below Exercises63 teaches foreign key ID references instructor foreign key course id sec id semester year references sec course takes foreign key ID references student foreign key course id sec id semester year references sec course prereq foreign key course id references course foreign key prereq id references course advisor foreign key s ID references student foreign key i id references instructor sec course foreign key course id references course foreign key sec id semester year references section sec time slot foreign key course id sec id semester year references sec course foreign key time slot id references time slot sec class foreign key course id sec id semester year references sec course foreign key building room number references classroom inst dept foreign key ID references instructor foreign key dept name referen
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 大班建构积木活动指南
- 儿童国画鸡课件
- 时间位移课件
- 时钟变时间尺课件
- 2025版高端餐饮连锁加盟合作协议
- 2025版体育赛事赞助担保合同
- 二零二五版房屋代理买卖合同(含市场分析)
- 二零二五年度板材库存管理与购销合同
- 2025版餐饮企业承包合同标准模板下载
- 2025版第一部分智慧交通建设项目投标邀请合同
- 2024年成都新都投资集团有限公司招聘笔试真题
- 新人教版九年级下册初中化学全册课前预习单
- 加药系统改造方案(共6页)
- 内蒙古电网典型事故分析
- 工厂规章制度员工守则.doc
- 螺栓各部位的英文名称
- 线性代数:矩阵2-1矩阵的概念
- 精品]上海市单位退工证明
- 医疗质量与安全分析报告范文
- 600MW机组两车台吊发电机定子吊装方案
- 商铺销售基础知识培训
评论
0/150
提交评论