Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 3630 Database Design and Implementation. 2 E-R Model (II) Keys To identify records in a table Candidate Key Primary Key Alternate Key Composite Key.

Similar presentations


Presentation on theme: "CS 3630 Database Design and Implementation. 2 E-R Model (II) Keys To identify records in a table Candidate Key Primary Key Alternate Key Composite Key."— Presentation transcript:

1 CS 3630 Database Design and Implementation

2 2 E-R Model (II) Keys To identify records in a table Candidate Key Primary Key Alternate Key Composite Key

3 3 Candidate Key A minimum set of attributes that uniquely identifies each occurrence of an entity type. No proper subset satisfying the definition. Not minimum cardinality. R (Att1, Att2, Att3, Att4, Att5) Candidate Key: (Att1, Att2) Either Att1 or Att2 is not a candidate key But Att3 could be a candidate key An entity type could have more than one candidate key. Attributes of a candidate key cannot have null values.

4 4 List the Candidate Keys Branch (branchNo, street, city, state, zipcode) branchNostreetcitystatezipcode b0011 Main stMadisonWI53708 b01215 Washington stMadisonWI53708 b0511 Main stPlattevilleWI53818 ……………

5 5 List the Candidate Keys Owner (ownerNo, firstName, lastName, address, telNo) ownerNofirstNamelastNameaddresstelNo O101ScottSummers23 Moon Night, Platteville, WI, 538181421 O203MikeRowe100 Madison, Platteville, WI, 538181556 O318QiYang213 Ullrich, Platteville, WI, 538181418 ……………

6 6 List the Candidate Keys Viewing (clientNo, propertyNo, viewDate, viewTime, comment) clientNopropertyNoviewDateviewTimecomment V100P10211/1/201410:00too large V221P20211/5/201311:30Expensive V100P10211/21/20142:15looks nice ……………

7 7 Primary/Alternate Key Primary Key (PK) The candidate key that is selected to uniquely identify each occurrence of an entity type. Alternate key (AK) candidate key, but not primary key still unique One entity type one PK zero or more AKs

8 8 Primary/Alternate Key Branch (branchNo, street, city, state, zipcode) PK: branchNo AK: street, city, state, zipcode Owner (ownerNo, firstName, lastName, address, telNo) PK: ownerNo AK: None Viewing (clientNo, propertyNo, viewDate, viewTime, comment) PK: clientNo, viewDate, viewTime AK: propertyNo, viewDate, viewTime

9 9 Simple and Composite Key Branch (branchNo, street, city, state, zipcode) Simple Owner (ownerNo, firstName, lastName, address, telNo) Simple Viewing (clientNo, propertyNo, viewDate, viewTime, comment) Composite

10 10 Example Table Schema R (A, B, C) Table Instance A B C 100 x ct 200 y se 200 x cis Any candidate keys? Business rules. Part of table schema. Cannot be decided based on table instance only.

11 11 Diagrammatic Representation of Attributes Branch branchNo {PK} address … Branch branchNo Branch branchNo address … Only show the PKs in ER diagram.

12 12 Strong and Weak Entity Strong Entity not existence-dependent on other entity Weak Entity existence-dependent on other entity Business rules!

13 13 Strong and Weak Entity Patient patientNo Next_Of_Kin {PK?} Has Strong entity Must have PK Parent Owner Dominant Weak entity May not have PK Child Dependent Subordinate

14 14 Structural Constraints Business Rules Participation Total (Mandatory) Partial (Optional) Cardinality Max number of occurrences that can be related to one occurrence Staff Oversees PropertyForRent

15 15 Structural Constraints: Multiplicity Combination of Participation and Cardinality Multiplicity of Binary Relationship one-to-one one-to-many many-to-many

16 16 Multiplicity: one-to-one Staff staffNo Branch branchNo Staff (1..1) Manages (0..1) Branch 1..1 0..1 Each branch has exactly one manager. Each staff manages zero or one branch. For one object on the other side! Manages

17 17 Multiplicity: one-to-many Staff staffNo PropertyForRent propertyNo Staff (0..1) Oversees (0..*) PropertyForRent 0..1 0..* For one object on the other side! One property is managed by 0 or 1 staff One staff manages 0 or more properties Oversees

18 18 Multiplicity: many-to-many NewsPaper newspaperName PropertyForRent propertyNo NewsPaper (0..*) Advertises (1..*) PropertyForRent 0..* 1..* For one object on the other side! One property is advertised on zero or more newspapers One newspaper has Ads for 1 or more properties Advertises

19 19 Structural Constraints: Multiplicity Multiplicity of Complex Relationship (n-ary) When (n-1) values are fixed for other entities

20 20 Multiplicity for Complex Relationship BranchStaff Client Registers 0..* 0..1 Client (0..*) Registers with Staff (0..1) at Branch (0..1)

21 21 Assignment 3 Due Friday, Feb 13, beginning of class Do it with another student in the same section Sample E-R Model

22 Quiz1 Wednesday, Lab 206 Using Computers Open everything, but do it yourself! Download Word Document from D2L Upload Completed Document to D2L 22


Download ppt "CS 3630 Database Design and Implementation. 2 E-R Model (II) Keys To identify records in a table Candidate Key Primary Key Alternate Key Composite Key."

Similar presentations


Ads by Google