数据库系统课件:ch6 Entity-Relationship Model_第1页
数据库系统课件:ch6 Entity-Relationship Model_第2页
数据库系统课件:ch6 Entity-Relationship Model_第3页
数据库系统课件:ch6 Entity-Relationship Model_第4页
数据库系统课件:ch6 Entity-Relationship Model_第5页
已阅读5页,还剩90页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Chapter 6: Entity-Relationship ModelChapter 6: Entity-Relationship ModelDesign ProcessModelingConstraintsE-R Diagram Design Issues Weak Entity Sets Extended E-R FeaturesDesign of the Bank DatabaseReduction to Relation SchemasDatabase DesignUMLModelingA database can be modeled as:a collection of enti

2、ties,relationship among entities.An entity is an object that exists and is distinguishable from other objects.Example: specific person, company, event, plantEntities have attributesExample: people have names and addressesAn entity set is a set of entities of the same type that share the same propert

3、ies.Example: set of all persons, companies, trees, holidaysEntity Sets customer and loancustomer_idcustomer_namecustomer_streetcustomer_cityloan_numberamountRelationship SetsA relationship is an association among several entitiesExample:Hayes borrower L-15customer entity relationship set loan entity

4、A relationship set is a mathematical relation among n 2 entities, each taken from entity sets(e1, e2, en) | e1 E1, e2 E2, , en Enwhere (e1, e2, , en) is a relationshipExample: (Hayes, A-102) depositorRelationship Set borrowerRelationship Sets (Cont.)An attribute can also be property of a relationshi

5、p set.For instance, the depositor relationship set between entity sets customer and account may have the attribute access-dateDegree of a Relationship SetRefers to number of entity sets that participate in a relationship set.Relationship sets that involve two entity sets are binary (or degree two).

6、Generally, most relationship sets in a database system are binary.Relationship sets may involve more than two entity sets. Relationships between more than two entity sets are rare. Most relationships are binary. (More on this later.)Example: Suppose employees of a bank may have jobs (responsibilitie

7、s) at multiple branches, with different jobs at different branches. Then there is a ternary relationship set between entity sets employee, job, and branchE-R Diagram with a Ternary RelationshipTwo example works-on relationships: (John, Wushan branch, manager)(John, Beijing Street branch, auditor) Th

8、ey indicate that John takes different roles in the two branches.AttributesAn entity is represented by a set of attributes, that is descriptive properties possessed by all members of an entity set.Domain the set of permitted values for each attribute Attribute types:Simple and composite attributes.Si

9、ngle-valued and multi-valued attributesExample: multivalued attribute: phone_numbersDerived attributesCan be computed from other attributesExample: age, given date_of_birthExample: customer = (customer_id, customer_name, customer_street, customer_city )loan = (loan_number, amount )Composite Attribut

10、esMapping Cardinality ConstraintsExpress the number of entities to which another entity can be associated via a relationship set.Most useful in describing binary relationship sets.For a binary relationship set the mapping cardinality must be one of the following types:One to oneOne to manyMany to on

11、eMany to many Mapping CardinalitiesOne to oneOne to manyNote: Some elements in A and B may not be mapped to any elements in the other setMapping Cardinalities Many to oneMany to manyNote: Some elements in A and B may not be mapped to any elements in the other setKeysA super key of an entity set is a

12、 set of one or more attributes whose values uniquely determine each entity.A candidate key of an entity set is a minimal super keyCustomer_id is candidate key of customeraccount_number is candidate key of accountAlthough several candidate keys may exist, one of the candidate keys is selected to be t

13、he primary key.Keys for Relationship SetsThe combination of primary keys of the participating entity sets forms a super key of a relationship set.(customer_id, account_number) is the super key of depositorNOTE: this means a pair of entity sets can have at most one relationship in a particular relati

14、onship set. Example: if we wish to track all access_dates to each account by each customer, we cannot assume a relationship for each access. We can use a multivalued attribute though(321-12-3123, A-101, 2008-09-13)(321-12-3123, A-101, 2008-09-14)Must consider the mapping cardinality of the relations

15、hip set when deciding what are the candidate keys Need to consider semantics of relationship set in selecting the primary key in case of more than one candidate keyNO, because no two tuples can have the same keyE-R DiagramsRectangles represent entity sets.Diamonds represent relationship sets.Lines l

16、ink attributes to entity sets and entity sets to relationship sets.Ellipses represent attributesDouble ellipses represent multivalued attributes.Dashed ellipses denote derived attributes.Underline indicates primary key attributes (will study later)E-R Diagram With Composite, Multivalued, and Derived

17、 Attributesderived attributemulti-valued attributeRelationship Sets with AttributesRolesEntity sets of a relationship need not be distinctThe labels “manager” and “worker” are called roles; they specify how employee entities interact via the works_for relationship set.Roles are indicated in E-R diag

18、rams by labeling the lines that connect diamonds to rectangles.Role labels are optional, and are used to clarify semantics of the relationshipCardinality ConstraintsWe express cardinality constraints by drawing either a directed line (), signifying “one,” or an undirected line (), signifying “many,”

19、 between the relationship set and the entity set.One-to-one relationship:A customer is associated with at most one loan via the relationship borrowerA loan is associated with at most one customer via borrowerOne-To-One RelationshipIn the one-to-one relationship a loan is associated with at most one

20、customer via borrower, a customer is associated with at most one loans via borroweroneOne-To-Many RelationshipIn the one-to-many relationship a loan is associated with at most one customer via borrower, a customer is associated with several (including 0) loans via borroweronemanyMany-To-One Relation

21、shipsIn a many-to-one relationship a loan is associated with several (including 0) customers via borrower, a customer is associated with at most one loan via borrowermanyoneMany-To-Many RelationshipA customer is associated with several (possibly 0) loans via borrowerA loan is associated with several

22、 (possibly 0) customers via borrowerKeysPrimary keys of entities are underlined in an ER diagram.Keys for relationship setsAttributes that can uniquely identify a relationship in the relationship set.The union of the primary keys of the participating entity sets contains the primary key of a relatio

23、nship set.Customer-id, loan-number can uniquely decide each borrower relationship.But it is not a primary key it may not be minimum.Keys for 1-to-1 relationship setsThe primary key can be customer-id or loan-number.Keys for 1-m and m-m relationship setsPrimary key is loan_numberPrimary key is custom

24、er-id, loan_numberParticipation constraintTotal participation: Every entity in the entity set must participate in at least one relationship.Partial participation: Some entities may not participate. Some customers may not borrow any loan.Every loan must be borrowed by at least one customer.totalparti

25、alDesign IssuesUse of entity sets vs. attributesChoice mainly depends on the structure of the enterprise being modeled, and on the semantics associated with the attribute in question.Use of entity sets vs. relationship setsPossible guideline is to designate a relationship set to describe an action t

26、hat occurs between entitiesBinary versus n-ary relationship setsAlthough it is possible to replace any nonbinary (n-ary, for n 2) relationship set by a number of distinct binary relationship sets, a n-ary relationship set shows more clearly that several entities participate in a single relationship.

27、Placement of relationship attributesUse of entity sets vs. attributesUse of entity sets vs. attributesemployee-id employee-nameemployee-streetemployee-citytelephone 1telephone 21JonesMainHarrison602-346-356null2SmithNorthRye843-235-575843-089-2343WilliamsNassauHarrison602-346-356nullemployee-id empl

28、oyee-nameemployee-streetemployee-citytelephone1JonesMainHarrison602-346-3562SmithNorthRye843-235-5752SmithNorthRye843-089-2343WilliamsNassauHarrison602-346-356(a)Use of entity sets vs. attributesemployee-id telephone1602-346-3562843235-5753602-346-356telephonetelephone-companymanufactur

29、e-date602-346-356Telus2000.06843-235-575Telcom1998.11843-089-234AT&T2007.02employee-id employee-nameemployee-streetemployee-city1JonesMainHarrison2SmithNorthRye3WilliamsNassauPrinceton(b)Use of entity sets vs. relationship setsUse of entity sets vs. relationship setscustomer-id loan-numberbranch-nam

30、eamount1L-12Downtown2502L-11Redwood9003L-14Perryridge1500If every loan is held by exactly one customer and is associated with exactly one branch, the above design is satisfied.customer-id loan-numberbranch-nameamount1L-12Downtown2502L-11Redwood9003L-12Downtown250If several customers hold a loan join

31、tly, we must replicate the values for the descriptive attributes such as loan_number and amount.Binary Vs. Non-Binary RelationshipsSome relationships that appear to be non-binary may be better represented using binary relationshipsE.g. A ternary relationship parents, relating a child to his/her fath

32、er and mother, is best replaced by two binary relationships, father and motherUsing two binary relationships allows partial information (e.g. only mother being know)But there are some relationships that are naturally non-binaryExample: works_onConverting Non-Binary Relationships to Binary FormIn gen

33、eral, any non-binary relationship can be represented using binary relationships by creating an artificial entity set.Replace R between entity sets A, B and C by an entity set E, and three relationship sets: 1. RA, relating E and A 2.RB, relating E and B3. RC, relating E and CCreate a special identif

34、ying attribute for EAdd any attributes of R to E For each relationship (ai , bi , ci) in R, create 1. a new entity ei in the entity set E 2. add (ei , ai ) to RA 3. add (ei , bi ) to RB 4. add (ei , ci ) to RCnamebranchjobAdaDmJonesDaJonesPmEname1Ada2Jones3JonesEbranch1D2D3PEjob1m2a3mConverting Non-

35、Binary Relationships to Binary FormThe extra relationship sets and its attributes may increase the complexity of the design and overall storage requirements.A n-ary relationship set shows more clearly that several entities participate in a single relationship.Jones is a manager at PerryridgeHe also

36、is a auditor at DowntownConverting Non-Binary Relationships (Cont.)Also need to translate constraintsTranslating all constraints may not be possibleThere may be instances in the translated schema that cannot correspond to any instance of RWe can avoid creating an identifying attribute by making E a

37、weak entity set (described shortly) identified by the three relationship sets Placement of relationship attributesThe cardinality ratio of a relationship can affect the placement of relationship attributes.For instance, the attribute access_data specifies the most recent date on which a customer acc

38、essed that account.Mapping Cardinalities affect ER DesignCan make access-date an attribute of account, instead of a relationship attribute, if each account can have only one customer That is, the relationship from account to customer is many to one, or equivalently, customer to account is one to man

39、y首先确定实体类型:几个实体类型及相应的实体名确定联系类型:各实体类型之间是否有联系,是何种联系类型及相应的联系名连接实体类型和联系类型,组合成E-R图确定实体类型和联系类型的属性确定实体类型的码 设计E-R图过程(方法一)E-R模型例:学生选修课程学生课程选修姓名学号系别课程号课程名学分成绩用矩形表示实体用椭圆表示实体的属性用无向边把实体与其属性连接起来用菱形表示实体间的联系实体与联系用线段连接并注明类型mnE-R模型确定实体类型的码首先确定实体类型:几个实体类型及相应的实体名确定实体类型的属性;确定联系类型,及其属性;把实体类型和联系类型组合成E-R图;加上实体和联系的属性,并确定实体类型

40、的码。设计E-R图过程(方法二)E-R模型物资管理涉及的实体有:仓库零件 供应商 项目 职工例:构造某个工厂物资管理的E-R模型确定这些实体的属性有:仓库 属性有仓库号、面积、电话号码。零件 属性有零件号、名称、规格、单价、描述。供应商 属性有供应商号、姓名、地址、电话号码、账号。项目 属性有项目号、预算、开工日期。职工 属性有职工号、姓名、年龄、职称。E-R模型E-R模型确定这些实体之间的联系如下: 一个仓库可以存放多种零件,一种零件可以存放在多个仓库中,因此仓库和零件具有多对多的联系。用库存量来表示某种零件在某个仓库中的数量。一个仓库有多个职工当仓库保管员,一个职工只能在一个仓库工作,因此

41、仓库和职工之间是一对多的联系。职工之间具有领导-被领导关系。即仓库主任领导若干保管员,因此职工实体集中具有一对多的联系。供应商、项目和零件三者之间具有多对多的联系。即一个供应商可以供给若干项目多种零件,每个项目可以使用不同供应商供应的零件,每种零件可由不同供应商供给。E-R模型E-R模型确定联系的属性画出完整E-R图并确定码E-R模型Weak Entity SetsAn entity set that does not have a primary key is referred to as a weak entity set.The existence of a weak entity se

42、t depends on the existence of a identifying entity set it must relate to the identifying entity set via a total, one-to-many relationship set from the identifying to the weak entity setIdentifying relationship depicted using a double diamondThe discriminator (or partial key) of a weak entity set is

43、the set of attributes that distinguishes among all the entities of a weak entity set that depend on one particular strong entity.The primary key of a weak entity set is formed by the primary key of the strong entity set on which the weak entity set is existence dependent, plus the weak entity sets d

44、iscriminator.Weak Entity Sets (Example)loan_numberamountPayment_numberPayment_datePayment_amountL1234500012007.10.123000L1234500022007.11.121000L1234500032007.12.121000L5678700012007.10.123000L5678700022007.11.122000L5678700032007.12.122000Weak Entity Sets (Cont.)We depict a weak entity set by doubl

45、e rectangles.We underline the discriminator of a weak entity set with a dashed line.payment_number discriminator of the payment entity set Primary key for payment (loan_number, payment_number) Weak Entity Sets (Cont.)Note: the primary key of the strong entity set is not explicitly stored with the we

46、ak entity set, since it is implicit in the identifying relationship.If loan_number were explicitly stored, payment could be made a strong entity, but then the relationship between payment and loan would be duplicated by an implicit relationship defined by the attribute loan_number common to payment

47、and loanWeak Entity Sets (Cont.)In some case, the data base designer may choose to express a weak entity set as a multivalued composite attribute of the owner entity set.If it participates in only the identifying relationshipAnd if it has few attributesCustomerborrowerMore Weak Entity Set ExamplesIn

48、 a university, a course is a strong entity and a course_offering can be modeled as a weak entityThe discriminator of course_offering would be semester (including year) and section_number (if there is more than one section)If we model course_offering as a strong entity we would model course_number as

49、 an attribute. Then the relationship with course would be implicit in the course_number attributeExtended E-R Features: SpecializationTop-down design process; we designate subgroupings within an entity set that are distinctive from other entities in the set.These subgroupings become lower-level enti

50、ty sets that have attributes or participate in relationships that do not apply to the higher-level entity set.Depicted by a triangle component labeled ISA (E.g. customer “is a” person).Attribute inheritance a lower-level entity set inherits all the attributes and relationship participation of the hi

51、gher-level entity set to which it is linked.Specialization ExampleExtended ER Features: GeneralizationA bottom-up design process combine a number of entity sets that share the same features into a higher-level entity set.Specialization and generalization are simple inversions of each other; they are

52、 represented in an E-R diagram in the same way.The terms specialization and generalization are used interchangeably.Generalization本科生学生ISA硕士博士研究生ISA姓名学号DissertationPapers军训姓名工龄教职工ISA教师级别工号Specialization and Generalization (Cont.)Can have multiple specializations of an entity set based on different f

53、eatures. E.g. permanent_employee vs. temporary_employee, in addition to officer vs. secretary vs. tellerEach particular employee would be a member of one of permanent_employee or temporary_employee, and also a member of one of officer, secretary, or tellerThe ISA relationship also referred to as sup

54、erclass - subclass relationshipDesign Constraints on a Specialization/GeneralizationConstraint on which entities can be members of a given lower-level entity set.condition-definedExample: all customers over 65 years are members of senior-citizen entity set; senior-citizen ISA person.user-definedDesi

55、gn Constraints on a Specialization/GeneralizationConstraint on whether or not entities may belong to more than one lower-level entity set within a single generalization.Disjointan entity can belong to only one lower-level entity set, e.g. StudentNoted in E-R diagram by writing disjoint next to the I

56、SA triangleOverlappingan entity can belong to more than one lower-level entity set, e.g. TeacherDesign Constraints on a Specialization/Generalization (Cont.)Completeness constraint - specifies whether or not an entity in the higher-level entity set must belong to at least one of the lower-level enti

57、ty sets within a generalization.total : an entity must belong to one of the lower-level entity setspartial: an entity need not belong to one of the lower-level entity setsAggregation Consider the ternary relationship works_on, which we saw earlier Suppose we want to record managers for tasks perform

58、ed by an employee at a branchAggregation Suppose we want to record managers for tasks performed by an employee at a branch Cannot represent which (branch, job) combinations of an employee are managed by which manager.works-formanagerworkerAggregation Suppose we want to record managers for tasks perf

59、ormed by an employee at a branch Some (employee, branch, job) combination may not have a managerAggregation Suppose we want to record managers for tasks performed by an employee at a branch There is redundant information since every combination (employee, branch, job ) in manages is also in works-on

60、.Aggregation (Cont.)Relationship sets works_on and manages represent overlapping informationEvery manages relationship corresponds to a works_on relationshipHowever, some works_on relationships may not correspond to any manages relationships So we cant discard the works_on relationshipEliminate this

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论