Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 6: Entity-Relationship Model. 6.2Unite International CollegeDatabase Management Systems Chapter 6: Entity-Relationship Model Modeling Constraints.

Similar presentations


Presentation on theme: "Chapter 6: Entity-Relationship Model. 6.2Unite International CollegeDatabase Management Systems Chapter 6: Entity-Relationship Model Modeling Constraints."— Presentation transcript:

1 Chapter 6: Entity-Relationship Model

2 6.2Unite International CollegeDatabase Management Systems Chapter 6: Entity-Relationship Model Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to Relation Schemas Database Design

3 6.3Unite International CollegeDatabase Management Systems Modeling A database can be modeled as: a collection of entities, relationship among entities. An entity is an object that exists and is distinguishable from other objects. Example: specific person, company, event, plant Entities have attributes Example: people have names and addresses An entity set is a set of entities of the same type that share the same properties. Example: set of all persons, companies, trees, holidays

4 6.4Unite International CollegeDatabase Management Systems Entity Sets customer and loan customer_id customer_ customer_ customer_ loan_ amount name street city number

5 6.5Unite International CollegeDatabase Management Systems Relationship Sets A relationship is an association among several entities Example: HayesdepositorA-102 customer entityrelationship setaccount entity A relationship set is a mathematical relation among n  2 entities, each taken from entity sets {(e 1, e 2, … e n ) | e 1  E 1, e 2  E 2, …, e n  E n } where (e 1, e 2, …, e n ) is a relationship Example: (Hayes, A-102)  depositor

6 6.6Unite International CollegeDatabase Management Systems Relationship Set borrower

7 6.7Unite International CollegeDatabase Management Systems 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

8 6.8Unite International CollegeDatabase Management Systems Degree 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 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 (responsibilities) at multiple branches, with different jobs at different branches. Then there is a ternary relationship set between entity sets employee, job, and branch

9 6.9Unite International CollegeDatabase Management Systems 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 attribute Attribute types: Simple and composite attributes. Single-valued and multi-valued attributes  Example: multivalued attribute: phone_numbers Derived attributes  Can be computed from other attributes  Example: age, given date_of_birth Example: customer = (customer_id, customer_name, customer_street, customer_city ) loan = (loan_number, amount )

10 6.10Unite International CollegeDatabase Management Systems Composite Attributes

11 6.11Unite International CollegeDatabase Management Systems Chapter 6: Entity-Relationship Model Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to Relation Schemas Database Design

12 6.12Unite International CollegeDatabase Management Systems Mapping Cardinality Constraints 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 one One to many Many to one Many to many

13 6.13Unite International CollegeDatabase Management Systems Mapping Cardinalities One to oneOne to many Note: Some elements in A and B may not be mapped to any elements in the other set

14 6.14Unite International CollegeDatabase Management Systems Mapping Cardinalities Many to oneMany to many Note: Some elements in A and B may not be mapped to any elements in the other set

15 6.15Unite International CollegeDatabase Management Systems Chapter 6: Entity-Relationship Model Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to Relation Schemas Database Design

16 6.16Unite International CollegeDatabase Management Systems E-R Diagrams Rectangles represent entity sets. Diamonds represent relationship sets. Lines link attributes to entity sets and entity sets to relationship sets. Ellipses represent attributes Double ellipses represent multivalued attributes. Dashed ellipses denote derived attributes. Underline indicates primary key attributes (will study later)

17 6.17Unite International CollegeDatabase Management Systems E-R Diagram With Composite, Multivalued, and Derived Attributes

18 6.18Unite International CollegeDatabase Management Systems Relationship Sets with Attributes

19 6.19Unite International CollegeDatabase Management Systems Roles Entity sets of a relationship need not be distinct The 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 labeling the lines that connect diamonds to rectangles. Role labels are optional, and are used to clarify semantics of the relationship

20 6.20Unite International CollegeDatabase Management Systems Cardinality Constraints We 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 customer is associated with at most one loan via the relationship borrower A loan is associated with at most one customer via borrower

21 6.21Unite International CollegeDatabase Management Systems One-To-Many Relationship In 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 borrower

22 6.22Unite International CollegeDatabase Management Systems 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

23 6.23Unite International CollegeDatabase Management Systems Many-To-Many Relationship A customer is associated with several (possibly 0) loans via borrower A loan is associated with several (possibly 0) customers via borrower

24 6.24Unite International CollegeDatabase Management Systems 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 relationship in the relationship set E.g. participation of loan in borrower is total  every loan must have a customer associated to it via borrower Partial participation: some entities may not participate in any relationship in the relationship set Example: participation of customer in borrower is partial

25 6.25Unite International CollegeDatabase Management Systems Alternative Notation for Cardinality Limits Cardinality limits can also express participation constraints

26 6.26Unite International CollegeDatabase Management Systems E-R Diagram with a Ternary Relationship

27 6.27Unite International CollegeDatabase Management Systems Cardinality Constraints on Ternary Relationship We allow at most one arrow out of a ternary (or greater degree) relationship to indicate a cardinality constraint E.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 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 from (A, B) is associated with a unique C entity, and each pair (A, C) is associated with a unique B Each alternative has been used in different formalisms To avoid confusion we outlaw more than one arrow

28 6.28Unite International CollegeDatabase Management Systems Chapter 6: Entity-Relationship Model Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to Relation Schemas Database Design

29 6.29Unite International CollegeDatabase Management Systems Weak Entity Sets An 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 set it must relate to the identifying entity set via a total, one-to-many relationship set from the identifying to the weak entity set Identifying relationship depicted using a double diamond The 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 set on which the weak entity set is existence dependent, plus the weak entity set’s discriminator.

30 6.30Unite International CollegeDatabase Management Systems Weak Entity Sets (Cont.) We depict a weak entity set by double 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)

31 6.31Unite International CollegeDatabase Management Systems Weak Entity Sets (Cont.) A weak entity set can participate in relationships other than the identifying relationship. The payment entity could participate in a relationship with the account entity set, identifying the account from which the payment was made. A weak entity set may participate as owner in an identifying relationship with another weak entity set. It is also possible to have a weak entity set with more than one identifying entity set.

32 6.32Unite International CollegeDatabase Management Systems More Weak Entity Set Examples In a university, a course is a strong entity and a course_offering can be modeled as a weak entity The 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 an attribute. Then the relationship with course would be implicit in the course_number attribute

33 6.33Unite International CollegeDatabase Management Systems Chapter 6: Entity-Relationship Model Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to Relation Schemas Database Design

34 6.34Unite International CollegeDatabase Management Systems E-R Design Decisions The use of an attribute or entity to represent an object. Whether a real-world concept is best expressed by an entity set or a relationship set. The use of a ternary relationship versus a pair of binary relationships. The use of a strong or weak entity set.

35 6.35Unite International CollegeDatabase Management Systems Entity vs. Attribute Should address be an attribute of Employees or an entity (connected to Employees by a relationship)? Depends upon the use we want to make of address information, and the semantics of the data:  If we have several addresses per employee, address must be an entity OR a multi-valued attribute.  If the structure (city, street, etc.) is important, e.g., we want to retrieve employees in a given city, address must be modeled as an entity.

36 6.36Unite International CollegeDatabase Management Systems Entity vs. Attribute (Contd.) Works_In4 does not allow an employee to work in a department for two or more periods. Similar to the problem of wanting to record several addresses for an employee: We want to record several values of the descriptive attributes for each instance of this relationship. Accomplished by introducing new entity set, Duration. name Employees ssn lot Works_In4 from to dname budget did Departments dname budget did name Departments ssn lot Employees Works_In4 Duration from to

37 6.37Unite International CollegeDatabase Management Systems Entity vs. Relationship First ER diagram OK if a manager gets a separate budget for each dept. What if a manager gets a budget that covers all managed depts? Redundancy: dbudget stored for each dept managed by manager. Misleading: Suggests dbudget associated with department- mgr combination. Manages2 name dname budget did Employees Departments ssn lot dbudget since dname budget did Departments Manages2 Employees name ssn lot since Managersdbudget ISA This fixes the problem!

38 6.38Unite International CollegeDatabase Management Systems Binary vs. Ternary Relationships If each policy is owned by just 1 employee, and each dependent is tied to the covering policy, first diagram is inaccurate. What are the additional constraints in the 2nd diagram? age pname Dependents Covers name Employees ssn lot Policies policyid cost Beneficiary age pname Dependents policyid cost Policies Purchaser name Employees ssn lot Bad design Better design

39 6.39Unite International CollegeDatabase Management Systems Binary vs. Ternary Relationships (Contd.) Previous example illustrated a case when two binary relationships were better than one ternary relationship. An example in the other direction: a ternary relation Contracts relates entity sets Parts, Departments and Suppliers, and has descriptive attribute qty. A ternary relationship is more natural.

40 6.40Unite International CollegeDatabase Management Systems Binary Vs. Non-Binary Relationships Some relationships that appear to be non-binary may be better represented using binary relationships E.g. A ternary relationship parents, relating a child to his/her father and mother, is best replaced by two binary relationships, father and mother  Using two binary relationships allows partial information (e.g. only mother being know) But there are some relationships that are naturally non-binary  Example: works_on

41 6.41Unite International CollegeDatabase Management Systems Converting Non-Binary Relationships to Binary Form In general, 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. R A, relating E and A 2.R B, relating E and B 3. R C, relating E and C Create a special identifying attribute for E Add any attributes of R to E For each relationship (a i, b i, c i ) in R, create 1. a new entity e i in the entity set E 2. add (e i, a i ) to R A 3. add (e i, b i ) to R B 4. add (e i, c i ) to R C

42 6.42Unite International CollegeDatabase Management Systems Chapter 6: Entity-Relationship Model Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to Relation Schemas Database Design

43 6.43Unite International CollegeDatabase Management Systems Extended E-R Features: Specialization Top-down design process; we designate subgroupings within an entity set that are distinctive from other entities in the set. These subgroupings become 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. customer “is a” person). Attribute inheritance – a lower-level entity set inherits all the attributes and relationship participation of the higher-level entity set to which it is linked.

44 6.44Unite International CollegeDatabase Management Systems Specialization Example

45 6.45Unite International CollegeDatabase Management Systems Extended ER Features: Generalization A 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 represented in an E-R diagram in the same way. The terms specialization and generalization are used interchangeably.

46 6.46Unite International CollegeDatabase Management Systems Specialization and Generalization (Cont.) Can have multiple specializations of an entity set based on different features. E.g. permanent_employee vs. temporary_employee, in addition to officer vs. secretary vs. teller Each particular employee would be a member of one of permanent_employee or temporary_employee, and also a member of one of officer, secretary, or teller The ISA relationship also referred to as superclass - subclass relationship

47 6.47Unite International CollegeDatabase Management Systems Design Constraints on a Specialization/Generalization Constraint on which entities can be members of a given lower-level entity set. condition-defined  Example: all customers over 65 years are members of senior-citizen entity set; senior-citizen ISA person. user-defined Constraint on whether or not entities may belong to more than one lower-level entity set within a single generalization. Disjoint  an entity can belong to only one lower-level entity set  Noted in E-R diagram by writing disjoint next to the ISA triangle Overlapping  an entity can belong to more than one lower-level entity set

48 6.48Unite International CollegeDatabase Management Systems Design 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 entity sets within a generalization. total : an entity must belong to one of the lower-level entity sets partial: an entity need not belong to one of the lower-level entity sets

49 6.49Unite International CollegeDatabase Management Systems Aggregation Consider the ternary relationship works_on, which we saw earlier Suppose we want to record managers for tasks performed by an employee at a branch

50 6.50Unite International CollegeDatabase Management Systems Aggregation (Cont.) Relationship sets works_on and manages represent overlapping information Every manages relationship corresponds to a works_on relationship However, some works_on relationships may not correspond to any manages relationships  So we can’t discard the works_on relationship Eliminate this redundancy via aggregation Treat relationship as an abstract entity Allows relationships between relationships Abstraction of relationship into new entity Without introducing redundancy, the following diagram represents: An employee works on a particular job at a particular branch An employee, branch, job combination may have an associated manager

51 6.51Unite International CollegeDatabase Management Systems E-R Diagram With Aggregation

52 6.52Unite International CollegeDatabase Management Systems Chapter 6: Entity-Relationship Model Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to Relation Schemas Database Design

53 6.53Unite International CollegeDatabase Management Systems E-R Diagram for a Banking Enterprise

54 6.54Unite International CollegeDatabase Management Systems Summary of Symbols Used in E-R Notation

55 6.55Unite International CollegeDatabase Management Systems In-Class Practice An E-R diagram can be viewed as a graph. What do the following mean in terms of the structure of an enterprise schema? The graph is disconnected.  If a pair of entity sets are connected by a path in an E-R diagram, the entity sets are related, though perhaps indirectly. A disconnected graph implies that there are pairs of entity sets that are unrelated to each other. If we split the graph into connected components, we have, in effect, a separate database corresponding to each connected component. The graph is acyclic.  As indicated in the answer to the previous part, a path in the graph between a pair of entity sets indicates a (possibly indirect) relationship between the two entity sets. If there is a cycle in the graph then every pair of entity sets on the cycle are related to each other in at least two distinct ways. If the E-R diagram is acyclic then there is a unique path between every pair of entity sets and, thus, a unique relationship between every pair of entity sets.

56 6.56Unite International CollegeDatabase Management Systems In-Class Practice Consider a university database for the scheduling of classrooms for final exams. This database could be modeled as four entity sets exam with attributes exam_id and time course with attributes name, department and c_number section with attributes s_number and enrollment, and dependent as a weak entity set on course room with attributes r_number, capacity, and building Show the E-R diagram illustrating the use of all three additional entity sets listed.

57 6.57Unite International CollegeDatabase Management Systems n Draw an E/R diagram to model project groups in CS3030. Keep in mind that l each enrolled student (identified by a PID) can work at most in one group. l Each project, identified uniquely by its name, can have multiple groups working on it. l Be sure to identify all the appropriate multiplicity and referential integrity constraints in the diagram. l Indicate key attributes in each entity set.

58 6.58Unite International CollegeDatabase Management Systems 58 Design Techniques 1. Express all constraints (you can express!) 2. Use and do not change terminology and class structure of the application domain 3. Keep it simple 1. Avoid defining entity types that do not serve any purpose 2. Don’t use an entity set when an attribute will do. Choose an entity set if it helps expressing constraints; otherwise, use an attribute. 4. Avoid redundancy (but derived attributes are okay)! 5. Limit the use of weak entity sets.

59 6.59Unite International CollegeDatabase Management Systems 59 Avoiding Redundancy Redundancy occurs when we say the same thing in two different ways. Redundancy wastes space and encourages inconsistency. The two instances of the same fact may become inconsistent if we change one and forget to change the other, related version.

60 6.60Unite International CollegeDatabase Management Systems 60 Example: Good BeersManfs ManfBy name This design gives the address of each manufacturer exactly once. nameaddr

61 6.61Unite International CollegeDatabase Management Systems 61 Example: Bad Beers name This design repeats the manufacturer’s address once for each beer. manfmanfAddr

62 6.62Unite International CollegeDatabase Management Systems 62 Don’t Overuse Weak Entity Sets Beginning database designers often doubt that anything could be a key by itself. They make all entity sets weak, supported by all other entity sets to which they are linked. In reality, we usually create unique ID’s for entity sets. We use weak entity sets when there is no capability of creating unique ID’s.

63 6.63Unite International CollegeDatabase Management Systems Summary of ER Diagram Design Conceptual design follows requirements analysis, Yields a high-level description of data to be stored ER model popular for conceptual design Constructs are expressive, close to the way people think about their applications. Basic constructs: entities, relationships, and attributes (of entities and relationships). Some additional constructs: weak entities, ISA hierarchies, and aggregation. Note: There are many variations on ER model.

64 6.64Unite International CollegeDatabase Management Systems Summary of ER Diagram Design(Contd.) Several kinds of integrity constraints can be expressed in the ER model: key constraints, participation constraints, and overlap/covering constraints for ISA hierarchies. Some constraints (notably, functional dependencies) cannot be expressed in the ER model. (e.g., z = x + y) Constraints play an important role in determining the best database design for an enterprise.

65 6.65Unite International CollegeDatabase Management Systems Summary of ER Diagram Design(Contd.) ER design is subjective. There are often many ways to model a given scenario! Analyzing alternatives can be tricky, especially for a large enterprise. Common choices include: Entity vs. attribute, entity vs. relationship, binary or n-ary relationship, whether or not to use ISA hierarchies, and whether or not to use aggregation. Ensuring good database design: resulting relational schema should be analyzed and refined further. FD information and normalization techniques are especially useful.

66 6.66Unite International CollegeDatabase Management Systems Alternative E-R Notation

67 6.67Unite International CollegeDatabase Management Systems Alternative E-R Notation (Cont.)

68 6.68Unite International CollegeDatabase Management Systems Chapter 6: Entity-Relationship Model Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to Relation Schemas

69 6.69Unite International CollegeDatabase Management Systems From ER Diagram to Relation Model So… how do we convert an ER diagram into a table?? Simple!! Basic Ideas:  Build a table for each entity set  Build a table for each relationship set if necessary (more on this later)  Make a column in the table for each attribute in the entity set  Indivisibility Rule and Ordering Rule  Primary Key

70 6.70Unite International CollegeDatabase Management Systems Example – Strong Entity Set SIDNameMajorGPA 1234JohnCS2.8 5678MaryEE3.6 Student SIDName Major GPA Advisor Professor SSNName Dept SSNNameDept 9999SmithMath 8888LeeCS

71 6.71Unite International CollegeDatabase Management Systems Representation of Weak Entity Set Weak Entity Set Cannot exists alone To build a table/schema for weak entity set Construct a table with one column for each attribute in the weak entity set Remember to include discriminator Augment one extra column on the right side of the table, put in there the primary key of the Strong Entity Set (the entity set that the weak entity set is depending on) Primary Key of the weak entity set = Discriminator + foreign key

72 6.72Unite International CollegeDatabase Management Systems Example – Weak Entity Set AgeNameParent_SID 10Bart1234 8Lisa5678 Student SIDName Major GPA Name Age Childrenowns * Primary key of Children is Parent_SID + Name

73 6.73Unite International CollegeDatabase Management Systems Representing Relationship Set For one-to-one relationship w/out total participation Build a table with two columns, one column for each participating entity set’s primary key. Add successive columns, one for each descriptive attributes of the relationship set (if any). For one-to-one relationship with one entity set having total participation Augment one extra column on the right side of the table of the entity set with total participation, put in there the primary key of the entity set without complete participation as per to the relationship.

74 6.74Unite International CollegeDatabase Management Systems Example – One-to-One Relationship Set SIDMaj_ID CoS_Degree 9999071234 8888055678 Student SIDName Major GPA ID Code Majorstudy * Primary key can be either SID or Maj_ID_Co Degree

75 6.75Unite International CollegeDatabase Management Systems Example – One-to-One Relationship Set SIDNameMajorGPALP_S/NHav_Cond 9999BartEconomy-4.0123-456Own 8888LisaPhysics4.0567-890Loan Student SIDName Major GPA S/N # LaptopHave * Primary key can be either SID or LP_S/N Condition Brand 1:1 Relationship

76 6.76Unite International CollegeDatabase Management Systems Representing Relationship Set For one-to-many relationship w/out total participation Same thing as one-to-one For one-to-many/many-to-one relationship with one entity set having total participation on “many” side Augment one extra column on the right side of the table of the entity set on the “many” side, put in there the primary key of the entity set on the “one” side as per to the relationship.

77 6.77Unite International CollegeDatabase Management Systems Example – Many-to-One Relationship Set SIDNameMajorGPAPro_SSNAd_Sem 9999BartEconomy-4.0123-456Fall 2006 8888LisaPhysics4.0567-890Fall 2005 Student SIDName Major GPA SSN Professor * Primary key of this table is SID Semester Name N:1 Relationship Dept Advisor

78 6.78Unite International CollegeDatabase Management Systems Representing Relationship Set For many-to-many relationship Same thing as one-to-one relationship without total participation. Primary key of this new schema is the union of the foreign keys of both entity sets. No augmentation approach possible…

79 6.79Unite International CollegeDatabase Management Systems Representing N-ary Relationship Intuitively Simple Build a new table with as many columns as there are attributes for the union of the primary keys of all participating entity sets. Augment additional columns for descriptive attributes of the relationship set (if necessary) The primary key of this table is the union of all primary keys of entity sets that are on “many” side That is it, we are done.

80 6.80Unite International CollegeDatabase Management Systems Example – N-ary Relationship Set P-Key1P-Key2A-KeyD-Attribute 999988886666Yes 123456783456No E-Set 1 P-Key1 Another Set * Primary key of this table is P-Key1 + P-Key2 D-Attribute A relationship A-Key E-Set 2 P-Key2

81 6.81Unite International CollegeDatabase Management Systems Weak entity You DON’T have to build a table/schema for the identifying relationship set once you have built a table/schema for the corresponding weak entity set Reason:  A special case of one-to-many with total participation  Reduce Redundancy

82 6.82Unite International CollegeDatabase Management Systems Composite Attribute Relational Model Indivisibility Rule Applies One column for each component attribute NO column for the composite attribute itself Professor SSNName Address SSNNameStreetCity 9999Dr. Smith50 1 st St.Fake City 8888Dr. Lee1 B St.San Jose StreetCity

83 6.83Unite International CollegeDatabase Management Systems Multivalue Attribute For each multivalue attribute in an entity set/relationship set Build a new relation schema with two columns One column for the primary keys of the entity set/relationship set that has the multivalue attribute Another column for the multivalue attributes. Each cell of this column holds only one value. So each value is represented as an unique tuple Primary key for this schema is the union of all attributes

84 6.84Unite International CollegeDatabase Management Systems Example – Multivalue attribute SIDNameMajorGPA 1234JohnCS2.8 5678HomerEE3.6 Student SIDName Major GPA Stud_SIDChildren 1234Johnson 1234Mary 5678Bart 5678Lisa 5678Maggie Children The primary key for this table is Student_SID + Children, the union of all attributes

85 6.85Unite International CollegeDatabase Management Systems Representing Class Hierarchy Two general approaches depending on disjointness and completeness For non-disjoint and/or non-complete class hierarchy:  create a table for each super class entity set according to normal entity set translation method.  Create a table for each subclass entity set with a column for each of the attributes of that entity set plus one for each attributes of the primary key of the super class entity set  This primary key from super class entity set is also used as the primary key for this new table

86 6.86Unite International CollegeDatabase Management Systems Example SSNSIDStatusMajorGPA 12349999FullCS2.8 56788888PartEE3.6 Student SIDStatus Major GPA SSNNameGender 1234HomerMale 5678MargeFemale Person Gender SSNName ISA

87 6.87Unite International CollegeDatabase Management Systems Representing Class Hierarchy Two general approaches depending on disjointness and completeness For disjoint AND complete mapping class hierarchy: DO NOT create a table for the super class entity set Create a table for each subclass entity set include all attributes of that subclass entity set and attributes of the superclass entity set Simple and Intuitive enough, need example?

88 6.88Unite International CollegeDatabase Management Systems Example SSNNameSIDMajorGPA 1234John9999CS2.8 5678Mary8888EE3.6 Student SID Major GPA SSNNameDept 1234HomerC.S. 5678MargeMath UIC people SSNName ISA Faculty Dept Disjoint and Complete mapping No table created for superclass entity set

89 6.89Unite International CollegeDatabase Management Systems Representing Aggregation Student Name SID Advisor Professor SSNName Dept Name Code member SIDCode 123404 567808 Primary Key of Advisor Primary key of Dept

90 End of Chapter 2


Download ppt "Chapter 6: Entity-Relationship Model. 6.2Unite International CollegeDatabase Management Systems Chapter 6: Entity-Relationship Model Modeling Constraints."

Similar presentations


Ads by Google