Lecture 4 DB
Lecture 4 DB
Lecture 4 DB
Saqib Hussain
5-2
5-3
Data type
Null status
Default values (if any)
Data constraints (if any)
5-5
Representing Relationships
1:1 Relationships
The maximum cardinality determines how
a relationship is represented
1:1 relationship
The key from one relation is placed in the
other as a foreign key
It does not matter which table receives the
foreign key but better to see participations
constraints.
5-6
Two relations are created, one for each of the participating entity types.
2.
The primary key of one of the relations is included as a foreign key in the other
relation.
You should include in the relation on the optional side of the relationship the foreign
key of the entity type that has the mandatory participation in the 1:1 relationship.
This approach will avoid the need to store null values in the foreign key attribute.
Any attributes associated with the relationship itself are also included in the
same relation as the foreign key.
Representing Relationships
5-9
Representing Relationships
1:N Relationships
Like a 1:1 relationship, a 1:N relationship
is saved by placing the key from one table
into another as a foreign key
However, in a 1:N the foreign key always
goes into the many-side of the relationship
The 1 side is called the parent
The N side is called the child
5-10
Representing Relationships
5-11
Representing Relationships
N:M Relationships
To create an N:M relationship, a new
table is created. This table is called
an intersection table
An intersection table has a composite
key consisting of the keys from each
of the tables that it connects
5-13
Representing Relationships
N:M Relationship Data Model
5-14
Representing Relationships
N:M Relationship Database Design
5-15
Representing Relationships
Association Relationships
When an intersection table has columns beyond
those in the primary key, the relationship is
called an association relationship
5-16
Representing Relationships
Recursive Relationships
A recursive relationship is a relationship that a
relation has with itself.
Recursive relationships adhere to the same
rules as the binary relationships.
1:1 and 1:M relationships are saved using foreign
keys
M:N relationships are saved by creating an
intersecting relation
5-17
Representing Relationships
Recursive Relationships Examples
5-18
foreign key
The example on the next page illustrates such a case representing a bill
of materials relationship among items that are assembled from other
items or components.
ERD
ERD
2.
3.