Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Session 2 Welcome: The fifth learning sequence “ Entity-Relationship Model -2“ E-R Model Recap : In the previous learning sequence, we discussed the.

Similar presentations


Presentation on theme: "1 Session 2 Welcome: The fifth learning sequence “ Entity-Relationship Model -2“ E-R Model Recap : In the previous learning sequence, we discussed the."— Presentation transcript:

1 1 Session 2 Welcome: The fifth learning sequence “ Entity-Relationship Model -2“ E-R Model Recap : In the previous learning sequence, we discussed the introduction to E-R model. Present learning: We shall explore the following definitions: - Keys in E-R MODEL. - Weak Entity. - Design techniques.

2 2 Entity-Relationship Model 2 Keys Weak entity sets

3 3 Keys uA key is a set of attributes for one entity set such that no two entities in this set agree on all the attributes of the key. wIt is allowed for two entities to agree on some, but not all, of the key attributes. uWe must designate a key for every entity set.

4 4 Keys in E/R Diagrams uUnderline the key attribute(s).

5 5 Example: a Multi-attribute Key Courses deptnumberhoursroom Note that hours and room could also serve as a key, but we must select only one key.

6 Keys uA super key of an entity set is a set of one or more attributes whose values uniquely determine each entity. uA candidate key of an entity set is a minimal super key wCustomer-id is candidate key of customer waccount-number is candidate key of account uAlthough several candidate keys may exist, one of the candidate keys is selected to be the primary key.

7 Chapter 3-7 Types of Attributes (1) uSimple wEach entity has a single atomic value for the attribute. For example, SSN or Sex. uComposite wThe attribute may be composed of several components. For example, Address (Apt#, House#, Street, City, State, ZipCode, Country) or Name (FirstName, MiddleName, LastName). Composition may form a hierarchy where some components are themselves composite. uMulti-valued wAn entity may have multiple values for that attribute. For example, Color of a CAR or PreviousDegrees of a STUDENT. Denoted as {Color} or {PreviousDegrees}.

8 Chapter 3-8 Types of Attributes (2) uIn general, composite and multi-valued attributes may be nested arbitrarily to any number of levels although this is rare. For example, PreviousDegrees of a STUDENT is a composite multi-valued attribute denoted by {PreviousDegrees (College, Year, Degree, Field)}.

9 Chapter 3-9 ENTITY SET corresponding to the ENTITY TYPE CAR car 1 ((ABC 123, TEXAS), TK629, Ford Mustang, convertible, 1999, (red, black)) car 2 ((ABC 123, NEW YORK), WP9872, Nissan 300ZX, 2-door, 2002, (blue)) car 3 ((VSY 720, TEXAS), TD729, Buick LeSabre, 4-door, 2003, (white, blue)). CAR Registration(RegistrationNumber, State), VehicleID, Make, Model, Year, (Color)

10 Chapter 3-10 SUMMARY OF ER-DIAGRAM NOTATION FOR ER SCHEMAS Meaning ENTITY TYPE WEAK ENTITY TYPE RELATIONSHIP TYPE IDENTIFYING RELATIONSHIP TYPE ATTRIBUTE KEY ATTRIBUTE MULTIVALUED ATTRIBUTE COMPOSITE ATTRIBUTE DERIVED ATTRIBUTE TOTAL PARTICIPATION OF E 2 IN R CARDINALITY RATIO 1:N FOR E 1 :E 2 IN R STRUCTURAL CONSTRAINT (min, max) ON PARTICIPATION OF E IN R Symbol E1E1 R E2E2 E1E1 R E2E2 R (min,max) E N

11 Participation of an Entity Set in a Relationship n Total participation (indicated by double line): every entity in the entity set participates in at least one relationship in the relationship set n E.g. participation of loan in borrower is total n every loan must have a customer associated to it via borrower n Partial participation: some entities may not participate in any relationship in the relationship set n E.g. participation of customer in borrower is partial

12 Participation of an Entity Set in a Relationship

13 13 Weak Entity Sets uOccasionally, entities of an entity set need “help” to identify them uniquely. uEntity set E is said to be weak if in order to identify entities of E uniquely, we need to follow one or more many- one relationships from E and include the key of the related entities from the connected entity sets.

14 14 Example uname is almost a key for football players, but there might be two with the same name. unumber is certainly not a key, since players on two teams could have the same number. uBut number, together with the Team related to the player by Plays-on should be unique.

15 15 In E/R Diagrams PlayersTeams Plays- on name number Double diamond for supporting many-one relationship. Double rectangle for the weak entity set.

16 16 Weak Entity-Set Rules uA weak entity set has one or more many-one relationships to other (supporting) entity sets. wNot every many-one relationship from a weak entity set need be supporting. uThe key for a weak entity set is its own underlined attributes and the keys for the supporting entity sets. wE.g., player-number and team-name is a key for Players in the previous example.

17 Weak Entity-Set (Cont.) uAn entity set that does not have a primary key is referred to as a weak entity set. uThe existence of a weak entity set depends on the existence of a identifying entity set w it must relate to the identifying entity set via a total, one- to-many relationship set from the identifying to the weak entity set wIdentifying relationship depicted using a double diamond uThe 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. uThe 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.

18 Weak Entity Sets (Cont.) uNote: 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. uIf 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 and loan

19 Weak Entity Sets (Cont.) uWe depict a weak entity set by double rectangles. uWe underline the discriminator of a weak entity set with a dashed line. upayment-number – discriminator of the payment entity set uPrimary key for payment – (loan- number, payment-number)

20 Organization Scenario 20

21 Chapter 3-21 ER DIAGRAM – Entity Types are: EMPLOYEE, DEPARTMENT, PROJECT, DEPENDENT

22 22 Design Techniques 1.Avoid redundancy. 2.Don’t use an entity set when an attribute will do.

23 23 Avoiding Redundancy uRedundancy occurs when we say the same thing in two different ways. uRedundancy wastes space and (more importantly) encourages inconsistency. wThe two instances of the same fact may become inconsistent if we change one and forget to change the other, related version.

24 24 Example: Good StudentsTeacher Advises name This design gives the address of each teacher exactly once. nameaddr

25 25 Example: Bad StudentTeachers Advises name This design states the adviser of a student twice: as an attribute and as a related entity. name Adviser addr

26 26 Example: Bad Students name This design repeats the adviser’s address once for each student; loses the address if there are temporarily no students for an adviser. AdviserAdviser-Address

27 27 Entity Sets Versus Attributes uAn entity set should satisfy at least one of the following conditions: wIt is more than the name of something; it has at least one non key attribute. or wIt is the “many” in a many-one or many- many relationship.

28 28 Example: Good StudentsTeacher Advises name Teachers deserves to be an entity set because of the nonkey attribute address. Students deserves to be an entity set because it is the “many” of the many-one relationship Advises. nameaddress

29 29 Example: Good Students name There is no need to make the adviser an entity set, because we record nothing about advisers besides their name. Adviser

30 30 Example: Bad StudentsTeachers Advises name Since the teacher is nothing but a name, and is not at the “many” end of any relationship, it should not be an entity set. name

31 31 E-R Diagram Summary: In this learning sequence, we discussed the keys and weak entity sets in Entity- Relationship diagram.

32 32 END


Download ppt "1 Session 2 Welcome: The fifth learning sequence “ Entity-Relationship Model -2“ E-R Model Recap : In the previous learning sequence, we discussed the."

Similar presentations


Ads by Google