DB Fundamentals Lecture # (6)

8/6/2023
Science
1
Islamic Republic of Afghanistan
Ministry of Higher Education
Computer Science Faculty
Database Fundamentals
8/6/2023
Science
2
Lecture #6
Entity Relationship (E-R) Model) (Continue)
8/6/2023
Science
3
Elements of ER Model…….
Entity relationship ( E-R ) Model involve different types of elements such us:
1 . Entity
2. Attribute
3. Relationship
8/6/2023
Science
4
3. Relationship :
A relationship is an association representing an interaction among
the instance of one or more entity types that is interest to the
organization
The relationship may be between different entities or between an
entity itself.
A relationship is established on the basis of interaction among these
entities.
For example : a relationship exist between employ and department
because the employ works on department
8/6/2023
Science
5
Attribute on Relationship
Some times there are some attributes that is represented in the time
of relationship.
These attributes have its own meaning in ER diagram.
That attribute which are represented in the time of relationship are
not associated or related to another entity, because these attributes are
the properties of relationship
For example : we have two entity TEACHER and COURSE
8/6/2023
Science
6
Example Attributes of Relationship
COMPLETE
8/6/2023
Science
7
Associative Entity :
Associative entity is a type of entity that associates the instance of one
or more entity types
Associative entity contain the attributes that are related to the
relationship, these attributes are not related to another entity which are
presented in the relationship
Associative entities are represented as rectangle with rounded corners.
In ER diagram the associative entity has independent meaning to end
user
8/6/2023
Science
8
Degree of Relationship :
Each relationship consist of many entities.
The degree of relationship is the number of entity types that
participate in the relationship is called degree of relationship.
There are three most common relationship degree in E-R model
1. Unary Relationship
2. Binary Relationship
3.Ternary Relationship
8/6/2023
Science
9
1.Unary Relationship :
Unary Relationship is a type of relationship that is established between
the instance of a single entity type or it is established between the instance
of same entity type.
PERSON
manage
Teach
Lives
with
8/6/2023
Science
10
2. Binary Relationship :
Binary Relationship is a type of relationship that is established between
the instance of two entity type
It is the most common type of relationship in data modeling
There are different types of binary relationship
1. One –to- one Relationship
2. One-to-many Relationship
3. Many-to-many Relationship
8/6/2023
Science
11
1.One-to-one Relationship :
This is a type of relationship is used when, for each instance in first
entity type there is only one instance in the second entity type.
And for each instance in the second entity type, there is only one
instance in the first entity type .
1
MANAGER
1
manage
BRANCH
The above relationship means that one manager manage one branch.
Similarly, one branch is manage by one manager.
8/6/2023
Science
12
Example of One to One Relationship
8/6/2023
Science
13
Example of One-to-One Relationship :
1
Has
COUNTRY
Has
1
PRESIDENT
The above relationship means that one country has one president.
Similarly, one president of only one country
1
CHAIRMAN
1
Run
UNIVERSITY
The above relationship means that one chairman run only one university.
Similarly, one university is run by one chairman
8/6/2023
Science
14
Example of One-to-One Relationship : MAYOR
1
MANAGER
1
Has
PROVINCE
1
1
8/6/2023
GOVERNER
1
1
CITY
BRANCH
Manage
Has
MAYOR
Science
15
2. One-to-Many Relationship :
This is a type of relationship is used when, for each instance in first
entity type there can be many instance in the second entity type.
And for each instance in the second entity type there is only one
instance in the first entity type.
1
M
Has
The above relationship means that one province can have many district,
but one district is only belong to one province.
8/6/2023
Science
16
One-to-Many Example
8/6/2023
Science
17
Many-to-One Example
8/6/2023
Science
18
Example of One-to-Many Relationship
1
M
Has
the above relation means that one faculty can have many departments,
but one department is only belong to one faculty.
1
M
Work
the above relationship means that in one department can work many
employ, but one employ can only work on one department
8/6/2023
Science
19
Example of One-to-Many Relationship
COUNTRY
Has
PROVINCE
Faculty
Has
DEPARTMENT
HASBAND
Has
WIFE
8/6/2023
Science
20
3. Many-to-Many Relationship :
Many-to-Many Relationship is a type of relationship used when, for
each instance in first entity type, there can be many instance in the second
entity type
And for each instance in second entity type, there can be many
instance in the first entity type
Study
The above relationship means, that one student may study more
course, and one course may be studied by more students
8/6/2023
Science
21
Many-to-Many Example
8/6/2023
Science
22
2. Many-to-Many Relationship :
Has
The above relationship means that one employ learn many skills and
one skill can be learned by many employees.