數(shù)據(jù)庫系統(tǒng)課件:ch6 Entity-Relationship Model_第1頁
數(shù)據(jù)庫系統(tǒng)課件:ch6 Entity-Relationship Model_第2頁
數(shù)據(jù)庫系統(tǒng)課件:ch6 Entity-Relationship Model_第3頁
數(shù)據(jù)庫系統(tǒng)課件:ch6 Entity-Relationship Model_第4頁
數(shù)據(jù)庫系統(tǒng)課件:ch6 Entity-Relationship Model_第5頁
已閱讀5頁,還剩90頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

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首先確定實體類型:幾個實體類型及相應(yīng)的實體名確定聯(lián)系類型:各實體類型之間是否有聯(lián)系,是何種聯(lián)系類型及相應(yīng)的聯(lián)系名連接實體類型和聯(lián)系類型,組合成E-R圖確定實體類型和聯(lián)系類型的屬性確定實體類型的碼 設(shè)計E-R圖過程(方法一)E-R模型例:學(xué)生選修課程學(xué)生課程選修姓名學(xué)號系別課程號課程名學(xué)分成績用矩形表示實體用橢圓表示實體的屬性用無向邊把實體與其屬性連接起來用菱形表示實體間的聯(lián)系實體與聯(lián)系用線段連接并注明類型mnE-R模型確定實體類型的碼首先確定實體類型:幾個實體類型及相應(yīng)的實體名確定實體類型的屬性;確定聯(lián)系類型,及其屬性;把實體類型和聯(lián)系類型組合成E-R圖;加上實體和聯(lián)系的屬性,并確定實體類型

40、的碼。設(shè)計E-R圖過程(方法二)E-R模型物資管理涉及的實體有:倉庫零件 供應(yīng)商 項目 職工例:構(gòu)造某個工廠物資管理的E-R模型確定這些實體的屬性有:倉庫 屬性有倉庫號、面積、電話號碼。零件 屬性有零件號、名稱、規(guī)格、單價、描述。供應(yīng)商 屬性有供應(yīng)商號、姓名、地址、電話號碼、賬號。項目 屬性有項目號、預(yù)算、開工日期。職工 屬性有職工號、姓名、年齡、職稱。E-R模型E-R模型確定這些實體之間的聯(lián)系如下: 一個倉庫可以存放多種零件,一種零件可以存放在多個倉庫中,因此倉庫和零件具有多對多的聯(lián)系。用庫存量來表示某種零件在某個倉庫中的數(shù)量。一個倉庫有多個職工當(dāng)倉庫保管員,一個職工只能在一個倉庫工作,因此

41、倉庫和職工之間是一對多的聯(lián)系。職工之間具有領(lǐng)導(dǎo)-被領(lǐng)導(dǎo)關(guān)系。即倉庫主任領(lǐng)導(dǎo)若干保管員,因此職工實體集中具有一對多的聯(lián)系。供應(yīng)商、項目和零件三者之間具有多對多的聯(lián)系。即一個供應(yīng)商可以供給若干項目多種零件,每個項目可以使用不同供應(yīng)商供應(yīng)的零件,每種零件可由不同供應(yīng)商供給。E-R模型E-R模型確定聯(lián)系的屬性畫出完整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本科生學(xué)生ISA碩士博士研究生ISA姓名學(xué)號DissertationPapers軍訓(xùn)姓名工齡教職工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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論