Download presentation
Presentation is loading. Please wait.
1
Database Systems Instructor Name: Lecture-11
2
Contents Keys STEPS TOWARDS NORMALIZED ERD
Resolve Composite Attributes Resolve Multivalued Attributes Resolve Binary Relationship Resolve One-to-Many Relationship Resolve Many-to-Many Relationship Resolve One-to-One Relationship 2
3
Contents – Contd. Resolve Unary Relationship
Resolve One-to-Many Unary Relationship Resolve Many-to-Many Unary Relationship 3
4
Keys Primary Key: An attribute or combination of attribute that uniquely identifies each row in a relation Composite Key: A primary key that consists of more than one attributes Foreign Key: An attribute in a relation that serves as primary key of another relation in the same database 4
5
Primary Key and Foreign Key Notations
5
6
Keys – Contd. The composite key of DEPEDENT entity may be Emp_id and Dependent_name Foreign Key is used when we must represent relationship between two entity types or relations Foreign Key is represented by dotted line 6
7
Removing Composite Attributes from ERD
Only the simple component attributes of composite attributes are included in Entity Type 7
8
Removing Composite Attributes from ERD - Example
(a) CUSTOMER entity type with composite attribute 8
9
Removing Composite Attributes from ERD - Example
(a) CUSTOMER entity type with component attribute CUSTOMER State Zip City Street 9
10
Removing Multivalued Attributes from ERD
Two Entities are created First Entity contains all the attributes of entity type except multivalued attribute Second Entity Type contains two attributes that forms the primary key in second relation First of the attribute is the Primary Key of first relation Second is multivalued attribute {Represent in ERD in class} 10
11
Weak Entities Include Primary key of identifying relation or Owner Entity in the Weak Entity Together with the Primary Key of Identifying relation and partial identifier of the weak entity it forms Primary Key of weak entity {Represent in ERD in class} 11
12
Weak Entities Include Primary key of identifying relation or Owner Entity in the Weak Entity Together with the Primary Key of Identifying relation and partial identifier of the weak entity it forms Primary Key of weak entity {Represent in ERD in class} 12
13
Weak Entities Include Primary key of identifying relation or Owner Entity in the Weak Entity Together with the Primary Key of Identifying relation and partial identifier of the weak entity it forms Primary Key of weak entity {Represent in ERD in class} 13
14
Resolve Binary Relationship
The procedure depends upon degree of relationship (Unary, Binary, Ternary) and Cardinalities of Relationship 14
15
Resolve Binary One-to-Many Relationship
Place the Primary Key attribute(s) of one-side of the relationship to many-side of the relationship 15
16
Resolve Binary Many-to-Many Relationship
Entities A and B are in Many-to-Many Relationship We Create a third Entity C We Place Primary Key of Entity A and Entity B in the Entity C as Foreign Key Entity C is called junction relation Both of Primary Keys of A and B are presented as composite Primary Key of C 16
17
Resolve Binary One-to-One Relationship
Primary Key of one Entity type is created as foreign key in the other entity type In a 1:1 relationship, the association in one direction is nearly always optional one, whilst the association in the other direction is mandatory one Include the foreign key in the optional side of the relation of the Primary Key of mandatory type of relation Avoid storing null values in the foreign key constraint 17
18
Resolve Binary One-to-One Relationship
a binary 1:1 relationship between NURSE and CARE_CENTER, where each care centre must have a nurse who is in charge of that centre – so the association from care centre to nurse is a mandatory one, while the association from nurse to care centre is an optional one (since any nurse may or may not be in charge of a care centre) 18
19
Resolve Binary One-to-One Relationship
19
20
Resolve Associative Entity Relationship
Resolve by introducing a junction relation Resolve with its unique identifier, if the identifier have separate meanings to the end user 20
21
Resolve Associative Entity Relationship
21
22
Resolve Unary Relationship
Unary Relationship is a relationship between the same Entity type Resolution approach is different than Binary Relationship in One-to-Many and Many-to-Many Relationship 22
23
Resolve One-to-Many Unary Relationship
A Foreign Key is added within the same Entity type, this foreign key references Primary Key of the same Entity and the domain must be same as of Primary Key domain This is also called recursive foreign key {Represent in ERD} 23
24
Resolve Many-to-Many Unary Relationship
Two Entities are created One for the Entity Type itself and other for Many-to-Many Relationship The primary key of the associative relation consists of two attributes, both taking their values from the primary key of the other relation Any non-key attribute of the relationship is included in the associative relation {Represent in ERD} 24
25
Resolve Many-to-Many Unary Relationship
(a) Bill-of-materials relationships (M:N) (b) ITEM and COMPONENT relations 25
26
Resolve Ternary Relationship
It is best to convert a ternary relationship to an associative entity in order to represent participation constraints more accurately. Firstly, we create a new associative relation. The default primary key of this relation consists of the three primary key attributes for the participating entities (sometimes additional attributes are required to form a unique primary key) These attributes then act in the role of foreign keys that reference the individual primary keys of the participating entity types . Any attributes of the associative entity type become attributes of the new relation 26
27
Resolve Ternary Relationship
The following Fig. Represents a PATIENT receiving a TREATMENT from a PHYSICIAN The associative entity type PATIENT_Treatment has the attributes Date, Time and Results and values of these are recorded for each instance of patient treatment The primary key attributes Patient_ID, Physician_ID and Treatment_Code become foreign keys in PATIENT_TREATMENT – these are components of its primary key but do not uniquely identify a given treatment, since a patient may receive the same treatment from the same physician on more than one occasion 27
28
Resolve Ternary Relationship
Does including the attribute ‘Date’ as part of the primary key (along with the other 3 attributes) result in a primary key? This would be so if a patient only receives one treatment from a given physician on a given date If this is not the case, we include Time as part of the primary key, which now consists of five attributes: Patient_ID, Physician_ID, Treatment_Code, Date and Time {ERD Representation} 28
29
Ternary Relationship with Associative Entity
29
30
Resolve Ternary Relationship with Associative Entity
30
31
Table with Constraints
CREATE TABLE Show ( show_id NUMBER NOT NULL, category_id NUMBER NOT NULL, act_id NUMBER NOT NULL, venue_id NUMBER NOT NULL, showdate DATE NULL, CONSTRAINT XPKShow PRIMARY KEY (show_id), CONSTRAINT FKShow_Cat FOREIGN KEY (category_id) REFERENCES Category, CONSTRAINT FKShow_Venue FOREIGN KEY (venue_id) REFERENCES Venue, CONSTRAINT FKShow_Act FOREIGN KEY (act_id) REFERENCES Act ); 31
32
???????????????? 32
33
Erroneous Relationship
Receives or summarize the data, transfer, translate or calculate data 33
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.