3. M:N unary relationship: A Subject may have
many other Subjects as prerequisites and each
Subject may be a prerequisite to many other
Subjects
1:M unary relationship:
An Employee may manage many Employees,
but an Employee is managed by only one
Employee
1:1 unary relationship:
A Person may be married to only one Person.
Dr.Girija Narasimhan
3
4. Binary Relationship
If there are two entities involved in relationship then it is
referred to as binary relationship.
Dr.Girija Narasimhan
4
5. Ternary Relationship
If there are three entities involved then it is called as ternary relationship and so on.
The University might need to record which
teachers taught which subjects in which
courses.
Dr.Girija Narasimhan
5
6. The cardinality of a relationship is the number of instances of entity B that can be
associated with entity A. There is a minimum cardinality and a maximum cardinality for
each relationship, with an unspecified maximum cardinality being shown as
N. Cardinality limits are usually derived from the organizations policies or external
constraints.
At the University, each Teacher can teach an
unspecified maximum number of subjects as
long as his/her weekly hours do not exceed 24
(this is an external constraint set by an
industrial award). Teachers may teach 0
subjects if they are involved in non teaching
projects. Therefore, the cardinality limits for
TEACHER are (O,N).
Dr.Girija Narasimhan
The University's policies state that each
Subject is taught by only one teacher,
but it is possible to have Subjects that
have not yet been assigned a
teacher. Therefore, the cardinality limits
for SUBJECT are (0,1).
6
9. DOMAIN CONSTRAINTS
Domain_name
Meaning
Data type
Age
Years of the person
Phone_no
Conduct number
Mark
size
number
3
number
Scored by Student
in Exam
number
Dr.Girija Narasimhan
8
3
Allowable value or range
<=110
Must be 8 digit and
<99999999 and
>90000000
>=0 and <=100
9
10. ENTITY Integrity CONSTRAINTS
Every relation must have primary key
Every primary key attribute is non- null and unique
Unique means, value of the primary key must
be different not be same.
Null is a value, suppose no other value not assign or apply.
Null is not zero (0) or blank (“ “)
Dr.Girija Narasimhan
10
12. ENTITY Integrity CONSTRAINTS
Null is a value, suppose no other value not assign or apply.
Null is not zero (0) or blank (“ “)
Not Null
Entity integrity not enforced
No null value allowed in the primary key
Dr.Girija Narasimhan
12
13. Referential Integrity
CONSTRAINTS
• Two tables have relationship or association then use foreign key
Why Referential Integrity constraints?
To maintain Consistency among rows of two relationship.
Rule:
Rule 1: Foreign key must match with primary key of the other
relation.
Rule 2: Otherwise, If it is not matching then Foreign key value must
be “NULL”
Dr.Girija Narasimhan
13
16. Referential Integrity CONSTRAINTS
Rule 1: Foreign key must match with primary key of the other relation.
CASCADING DELETE
PROHIBIT DELETE
Dr.Girija Narasimhan
16
18. CASCADING DELETE
If delete the Primary key table record, automatically the foreign key referencing
table record information also deleted.
For example: Suppose if I delete deptno 20 in DEPT table (master /parent),
automatically in the EMP table empno 6666 and Empno 7329 also deleted
because both are referencing deptno 20.
Dr.Girija Narasimhan
18
19. PROHIBIT DELETE
Before deleting primary key record, first delete all the foreign key associated
records in referencing table or child table.
For example: First delete EMP table empno 6666 and Empno 7329 and
then delete DEPT table deptno 20
Dr.Girija Narasimhan
19
20. Rule 2: Otherwise, If it is not matching then Foreign key value must be “NULL”
Place a null value in the Foreign key.
When?
Suppose I want to remove deptno 20 from DEPT TABLE, but I want to retain
or keep the employee 6666 and 7329 in the EMP table , then in the
foreign key attribute DEPTNO column in EMP table instead of 20 I will put
“Null” in both the record 6666 and 7329.
Dr.Girija Narasimhan
20
21. Mapping ER diagrams to Relations
Why?
Transform Conceptual model to Relational model
Entity type
Regular
Week entity type
Create a new relation
Composite
Binary Relations
Unary Relation
1-1 relation type
1-N relation type
M-N relation type
Multivalued
Dr.Girija Narasimhan
21
22. Mapping ER diagrams to Relations
Entity type
Regular
Dr.Girija Narasimhan
22
23. Mapping ER diagrams to Relations
Entity type
Dr.Girija Narasimhan
Composite
23
24. Mapping ER diagrams to Relations
Entity type
Dr.Girija Narasimhan
Multi valued
24
25. Mapping Weak Entities
weak entity type does not have an independent existence, but exists only through an
identifying relationship with another entity type called the owner or strong entity.
Dr.Girija Narasimhan
25
26. Mapping 1-1 Binary Relationship Type
Employee must assign
by only one
Employee may manage one or may
department.
not manage any department
One and only One (Mandatory One)
Zero or One (Optional One)
Using foreign key
Dr.Girija Narasimhan
26
27. Mapping 1-N Binary Relationship Type
Department have one
or more employee
One or More (Mandatory One)
Employee must work only
one department.
One and only One (Mandatory One)
Dr.Girija Narasimhan
27
28. Mapping M-N Binary Relationship Type
Employee join one
or more project
Project has one
more employee
One or More (Mandatory One)
One or More (Mandatory One)
Dr.Girija Narasimhan
28
29. Mapping Unary Relation Type
one employee appointed
as supervisor
Dr.Girija Narasimhan
29