CAS第二次课程实体关系模型.ppt
《CAS第二次课程实体关系模型.ppt》由会员分享,可在线阅读,更多相关《CAS第二次课程实体关系模型.ppt(73页珍藏版)》请在三一办公上搜索。
1、Chapter 2:Entity-Relationship Model,Entity SetsRelationship SetsDesign Issues Mapping Constraints KeysE-R DiagramExtended E-R FeaturesDesign of an E-R Database SchemaReduction of an E-R Schema to Tables,Entity Sets,A database can be modeled as:a collection of entities,relationship among entities.An
2、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 properties.Example:set of all persons,companies,
3、trees,holidays,Entity Sets customer and loan,customer-id customer-customer-customer-loan-amount name street city number,Attributes,An 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 attr
4、ibute Attribute types:Simple and composite attributes.Single-valued and multi-valued attributesE.g.multivalued attribute:phone-numbersDerived attributesCan be computed from other attributesE.g.age,given date of birth,Example:customer=(customer-id,customer-name,customer-street,customer-city)loan=(loa
5、n-number,amount),Composite Attributes,Relationship Sets,A relationship is an association among several entitiesExample:HayesdepositorA-102customer entityrelationship setaccount entityA relationship set is a mathematical relation among n 2 entities,each taken from entity sets(e1,e2,en)|e1 E1,e2 E2,en
6、 Enwhere(e1,e2,en)is a relationshipExample:(Hayes,A-102)depositor,Relationship Set borrower,Relationship Sets(Cont.),An attribute can also be property of a relationship set.For instance,the depositor relationship set between entity sets customer and account may have the attribute access-date,Degree
7、of a Relationship Set,Refers to number of entity sets that participate in a relationship set.Relationship sets that involve two entity sets are binary(or degree two).Generally,most relationship sets in a database system are binary.Relationship sets may involve more than two entity sets.Relationships
8、 between more than two entity sets are rare.Most relationships are binary.(More on this later.),E.g.Suppose employees of a bank may have jobs(responsibilities)at multiple branches,with different jobs at different branches.Then there is a ternary relationship set between entity sets employee,job and
9、branch,Mapping Cardinalities映射基数,Express 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
10、eMany to many,Mapping Cardinalities,One to one,One to many,Note:Some elements in A and B may not be mapped to any elements in the other set,Mapping Cardinalities,Many to one,Many to many,Note:Some elements in A and B may not be mapped to any elements in the other set,Mapping Cardinalities affect ER
11、Design,Can make access-date an attribute of account,instead of a relationship attribute,if each account can have only one customer I.e.,the relationship from account to customer is many to one,or equivalently,customer to account is one to many,E-R Diagrams,Rectangles represent entity sets.Diamonds r
12、epresent relationship sets.Lines link 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 C
13、omposite,Multivalued,and Derived Attributes,Relationship Sets with Attributes,Roles,Entity 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 diagrams by l
14、abeling the lines that connect diamonds to rectangles.Role labels are optional,and are used to clarify semantics of the relationship,Cardinality Constraints,We express cardinality constraints by drawing either a directed line(),signifying“one,”or an undirected line(),signifying“many,”between the rel
15、ationship set and the entity set.E.g.: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 borrower,One-To-Many Relationship,In the one-to-many relationship a loan is associated with at most one custome
16、r via borrower,a customer is associated with several(including 0)loans via borrower,Many-To-One Relationships,In 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 borrower,Many-To-Many Relationship,A cus
17、tomer is associated with several(possibly 0)loans via borrowerA loan is associated with several(possibly 0)customers via borrower,Participation of an Entity Set in a Relationship Set,Total participation(indicated by double line):every entity in the entity set participates in at least one relationshi
18、p in the relationship setE.g.participation of loan in borrower is total every loan must have a customer associated to it via borrowerPartial participation:some entities may not participate in any relationship in the relationship setE.g.participation of customer in borrower is partial,Alternative Not
19、ation for Cardinality Limits,Cardinality limits can also express participation constraints,Keys,A super key of an entity set is a 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 customera
20、ccount-number is candidate key of accountAlthough several candidate keys may exist,one of the candidate keys is selected to be the primary key.,Keys for Relationship Sets,The combination of primary keys of the participating entity sets forms a super key of a relationship set.(customer-id,account-num
21、ber)is the super key of depositorNOTE:this means a pair of entity sets can have at most one relationship in a particular relationship set.E.g.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 thoug
22、hMust consider the mapping cardinality of the relationship set when deciding the what are the candidate keys Need to consider semantics of relationship set in selecting the primary key in case of more than one candidate key,E-R Diagram with a Ternary Relationship,Cardinality Constraints on Ternary R
23、elationship,We allow at most one arrow out of a ternary(or greater degree)relationship to indicate a cardinality constraintE.g.an arrow from works-on to job indicates each employee works on at most one job at any branch.If there is more than one arrow,there are two ways of defining the meaning.E.g a
24、 ternary relationship R between A,B and C with arrows to B and C could mean1.each A entity is associated with a unique entity from B and C or 2.each pair of entities from(A,B)is associated with a unique C entity,and each pair(A,C)is associated with a unique BEach alternative has been used in differe
25、nt formalismsTo avoid confusion we outlaw more than one arrow,Binary Vs.Non-Binary Relationships,Some 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 father and mother,is best replaced by tw
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- CAS 第二次 课程 实体 关系 模型

链接地址:https://www.31ppt.com/p-5419153.html