山大數(shù)據(jù)庫(kù)系統(tǒng)英語(yǔ)課件07數(shù)據(jù)庫(kù)設(shè)計(jì)和ER模型_第1頁(yè)
山大數(shù)據(jù)庫(kù)系統(tǒng)英語(yǔ)課件07數(shù)據(jù)庫(kù)設(shè)計(jì)和ER模型_第2頁(yè)
山大數(shù)據(jù)庫(kù)系統(tǒng)英語(yǔ)課件07數(shù)據(jù)庫(kù)設(shè)計(jì)和ER模型_第3頁(yè)
山大數(shù)據(jù)庫(kù)系統(tǒng)英語(yǔ)課件07數(shù)據(jù)庫(kù)設(shè)計(jì)和ER模型_第4頁(yè)
山大數(shù)據(jù)庫(kù)系統(tǒng)英語(yǔ)課件07數(shù)據(jù)庫(kù)設(shè)計(jì)和ER模型_第5頁(yè)
已閱讀5頁(yè),還剩97頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、Chapter 7: Entity-Relationship ModelChapter 7: 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 instructor and studentinstructor_ID instructor_name student-ID student_nameRelationship SetsA relationship is an association among several entitiesExample: 44553 (Peltier) advisor 22222 (Einstein) student entityrelationship set i

4、nstructor entityA 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: (44553,22222) advisorRelationship Set advisorRelationship Sets (Cont.)An attribute can also be property of a

5、 relationship set.For instance, the advisor relationship set between entity sets instructor and student may have the attribute date which tracks when the student started being associated with the advisorDegree of a Relationship Setbinary relationshipinvolve two entity sets (or degree two). most rela

6、tionship sets in a database system are binary.Relationships between more than two entity sets are rare. Most relationships are binary. (More on this later.)Example: students work on research projects under the guidance of an instructor. relationship proj_guide is a ternary relationship between instr

7、uctor, student, and projectAttributesAn entity is represented by a set of attributes, that is descriptive properties possessed by all members of an entity set.Example: instructor = (ID, name, street, city, salary )course= (course_id, title, credits)Domain the set of permitted values for each attribu

8、te Attribute types:Simple and composite attributes.Single-valued and multivalued attributesExample: multivalued attribute: phone_numbersDerived attributesCan be computed from other attributesExample: age, given date_of_birthComposite AttributesMapping Cardinality ConstraintsExpress the number of ent

9、ities 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 oneMany to many Mapping CardinalitiesOne to oneOne to manyNo

10、te: 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 set of one or more attributes whose values uniquely deter

11、mine each entity.A candidate key of an entity set is a minimal super keyID is candidate key of instructorcourse_id is candidate key of courseAlthough several candidate keys may exist, one of the candidate keys is selected to be the primary key.Keys for Relationship SetsThe combination of primary key

12、s of the participating entity sets forms a super key of a relationship set.(s_id, i_id) is the super key of advisorNOTE: this means a pair of entity sets can have at most one relationship in a particular relationship set. Example: if we wish to track multiple meeting dates between a student and her

13、advisor, we cannot assume a relationship for each meeting. We can use a multivalued attribute thoughMust consider the mapping cardinality of the relationship 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

14、 one candidate keyRedundant AttributesSuppose we have entity setsinstructor, with attributes including dept_namedepartmentand a relationshipinst_dept relating instructor and departmentAttribute dept_name in entity instructor is redundant since there is an explicit relationship inst_dept which relate

15、s instructors to departmentsThe attribute replicates information present in the relationship, and should be removed from instructorBUT: when converting back to tables, in some cases the attribute gets reintroduced, as we will see.E-R DiagramsRectangles represent entity sets.Diamonds represent relati

16、onship sets.Attributes listed inside entity rectangleUnderline indicates primary key attributesEntity With Composite, Multivalued, and Derived AttributesRelationship Sets with AttributesRolesEntity sets of a relationship need not be distinctEach occurrence of an entity set plays a “role” in the rela

17、tionshipThe labels “course_id” and “prereq_id” are called roles.Cardinality ConstraintsWe express cardinality constraints by drawing either a directed line (), signifying “one,” or an undirected line (), signifying “many,” between the relationship set and the entity set.One-to-one relationship:A stu

18、dent is associated with at most one instructor via the relationship advisorA student is associated with at most one department via stud_deptOne-to-One Relationshipone-to-one relationship between an instructor and a studentan instructor is associated with at most one student via advisor and a student

19、 is associated with at most one instructor via advisorOne-to-Many Relationshipone-to-many relationship between an instructor and a student an instructor is associated with several (including 0) students via advisor a student is associated with at most one instructor via advisor, Many-to-One Relation

20、shipsIn a many-to-one relationship between an instructor and a student, an instructor is associated with at most one student via advisor, and a student is associated with several (including 0) instructors via advisorMany-to-Many RelationshipAn instructor is associated with several (possibly 0) stude

21、nts via advisorA student is associated with several (possibly 0) instructors via advisor Participation of an Entity Set in a Relationship SetTotal participation (indicated by double line): every entity in the entity set participates in at least one relationship in the relationship setE.g., participa

22、tion of section in sec_course is total every section must have an associated coursePartial participation: some entities may not participate in any relationship in the relationship setExample: participation of instructor in advisor is partialAlternative Notation for Cardinality LimitsCardinality limi

23、ts can also express participation constraintsE-R Diagram with a Ternary RelationshipCardinality Constraints on Ternary RelationshipWe allow at most one arrow out of a ternary (or greater degree) relationship to indicate a cardinality constraintE.g., an arrow from proj_guide to instructor indicates e

24、ach student has at most one guide for a projectIf there is more than one arrow, there are two ways of defining the meaning. E.g., a ternary relationship R between A, B and C with arrows to B and C could mean 1. each A entity is associated with a unique entity from B and C or 2. each pair of entities

25、 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 different formalismsTo avoid confusion we outlaw more than one arrowHow about doing an ER design interactively on the board?Suggest an application to be modeled.Weak

26、 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 set depends on the existence of a identifying entity setIt must relate to the identifying entity set via a total, one-to-many relationship set from the identifying to the wea

27、k entity setIdentifying relationship depicted using a double diamondThe discriminator (or partial key) of a weak entity set is the set of attributes that distinguishes among all the entities of a weak entity set.The primary key of a weak entity set is formed by the primary key of the strong entity s

28、et on which the weak entity set is existence dependent, plus the weak entity sets discriminator.Weak Entity Sets (Cont.)We underline the discriminator of a weak entity set with a dashed line.We put the identifying relationship of a weak entity in a double diamond. Primary key for section (course_id,

29、 sec_id, semester, year) Weak Entity Sets (Cont.)Note: the primary key of the strong entity set is not explicitly stored with the weak entity set, since it is implicit in the identifying relationship.If course_id were explicitly stored, section could be made a strong entity, but then the relationshi

30、p between section and course would be duplicated by an implicit relationship defined by the attribute course_id common to course and sectionE-R Diagram for a University EnterpriseReduction to Relational SchemasReduction to Relation SchemasEntity sets and relationship sets can be expressed uniformly

31、as relation schemas that represent the contents of the database.A database which conforms to an E-R diagram can be represented by a collection of schemas.For each entity set and relationship set there is a unique schema that is assigned the name of the corresponding entity set or relationship set.Ea

32、ch schema has a number of columns (generally corresponding to attributes), which have unique names.Representing Entity Sets With Simple AttributesA strong entity set reduces to a schema with the same attributesstudent(ID, name, tot_cred)A weak entity set becomes a table that includes a column for th

33、e primary key of the identifying strong entity set section ( course_id, sec_id, sem, year )Representing Relationship SetsA many-to-many relationship set is represented as a schema with attributes for the primary keys of the two participating entity sets, and any descriptive attributes of the relatio

34、nship set. Example: schema for relationship set advisoradvisor = (s_id, i_id)Redundancy of SchemasMany-to-one and one-to-many relationship sets that are total on the many-side can be represented by adding an extra attribute to the “many” side, containing the primary key of the “one” sideExample: Ins

35、tead of creating a schema for relationship set inst_dept, add an attribute dept_name to the schema arising from entity set instructorRedundancy of Schemas (Cont.)For one-to-one relationship sets, either side can be chosen to act as the “many” sideThat is, extra attribute can be added to either of th

36、e tables corresponding to the two entity sets If participation is partial on the “many” side, replacing a schema by an extra attribute in the schema corresponding to the “many” side could result in null valuesThe schema corresponding to a relationship set linking a weak entity set to its identifying

37、 strong entity set is redundant.Example: The section schema already contains the attributes that would appear in the sec_course schemaComposite and Multivalued AttributesComposite attributes are flattened out by creating a separate attribute for each component attributeExample: given entity set inst

38、ructor with composite attribute name with component attributes first_name and last_name the schema corresponding to the entity set has two attributes name_first_name and name_last_namePrefix omitted if there is no ambiguityIgnoring multivalued attributes, extended instructor schema isinstructor(ID,

39、first_name, middle_initial, last_name, street_number, street_name, apt_number, city, state, zip_code, date_of_birth)Composite and Multivalued AttributesA multivalued attribute M of an entity E is represented by a separate schema EMSchema EM has attributes corresponding to the primary key of E and an

40、 attribute corresponding to multivalued attribute MExample: Multivalued attribute phone_number of instructor is represented by a schema: inst_phone= ( ID, phone_number) Each value of the multivalued attribute maps to a separate tuple of the relation on schema EMFor example, an instructor entity with

41、 primary key 22222 and phone numbers 456-7890 and 123-4567 maps to two tuples: (22222, 456-7890) and (22222, 123-4567) Multivalued Attributes (Cont.)Special case:entity time_slot has only one attribute other than the primary-key attribute, and that attribute is multivaluedOptimization: Dont create t

42、he relation corresponding to the entity, just create the one corresponding to the multivalued attributetime_slot(time_slot_id, day, start_time, end_time)Caveat: time_slot attribute of section (from sec_time_slot) cannot be a foreign key due to this optimizationDesign IssuesUse of entity sets vs. att

43、ributesUse of phone as an entity allows extra information about phone numbers (plus multiple phone numbers)Design IssuesUse of entity sets vs. relationship setsPossible guideline is to designate a relationship set to describe an action that occurs between entitiesDesign IssuesBinary versus n-ary rel

44、ationship 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.Placement of relationship attributes e.g., attribu

45、te date as attribute of advisor or as attribute of studentBinary 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 father and mother, is best replaced by tw

46、o 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: proj_guideConverting Non-Binary Relationships to Binary FormIn general, any non-binary relationship

47、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 B 3. RC, relating E and CCreate a special identifying attribute for EAdd any attr

48、ibutes 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 RCConverting Non-Binary Relationships (Cont.)Also need to translate constraintsTranslating all constraints may not be possibl

49、eThere may be instances in the translated schema thatcannot correspond to any instance of RExercise: add constraints to the relationships RA, RB and RC to ensure that a newly created entity corresponds to exactly one entity in each of entity sets A, B and CWe can avoid creating an identifying attrib

50、ute by making E a weak entity set (described shortly) identified by the three relationship sets Extended ER FeaturesExtended 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 beco

51、me lower-level entity 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., instructor “is a” person).Attribute inheritance a lower-level entity set inherits all the attributes and relationship p

52、articipation of the higher-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 o

53、f each other; they are represented in an E-R diagram in the same way.The terms specialization and generalization are used interchangeably.Specialization and Generalization (Cont.)Can have multiple specializations of an entity set based on different features. E.g., permanent_employee vs. temporary_em

54、ployee, in addition to instructor vs. secretaryEach particular employee would be a member of one of permanent_employee or temporary_employee, and also a member of one of instructor, secretaryThe ISA relationship also referred to as superclass - subclass relationshipDesign Constraints on a Specializa

55、tion/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-definedConstraint on whether or not entities may belong to more than one low

56、er-level entity set within a single generalization.Disjointan entity can belong to only one lower-level entity setNoted in E-R diagram by having multiple lower-level entity sets link to the same triangleOverlappingan entity can belong to more than one lower-level entity setDesign Constraints on a Sp

57、ecialization/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 entity sets within a generalization.total: an entity must belong to one of the lower-level entity setspartial: an entity need

58、not belong to one of the lower-level entity setsAggregation Consider the ternary relationship proj_guide, which we saw earlier Suppose we want to record evaluations of a student by a guide on a projectAggregation (Cont.)Relationship sets eval_for and proj_guide represent overlapping informationEvery

59、 eval_for relationship corresponds to a proj_guide relationshipHowever, some proj_guide relationships may not correspond to any eval_for relationships So we cant discard the proj_guide relationshipEliminate this redundancy via aggregationTreat relationship as an abstract entityAllows relationships b

60、etween relationships Abstraction of relationship into new entityAggregation (Cont.)Without introducing redundancy, the following diagram represents:A student is guided by a particular instructor on a particular project A student, instructor, project combination may have an associated evaluationRepre

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論