0% found this document useful (0 votes)
2 views

Database Fundamentals

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Database Fundamentals

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 111

Nangarhar technical and vocational institute

Subject : Database fundamentals


semester : 2nd

------------------------------------------------------------

Omid Adel
 A collection of raw facts and figures is called data. The word
raw means that the facts have not yet been processed to get their
exact meaning.
Data is collected from different sources and collect for
different purpose which is most important and valuable for an
organization
Example of Data :
When students get admission in university, they have to fill
out an admission form consist of raw facts about the students.
These raw facts are students name, father name, phone no,
address etc which is valuable for an organization to maintain the
records of students during their study period in university

Omid Adel
Data may be the following types :
1. Numeric Data : Numeric data consist of numeric digits
from 0 to 9 like 20, 500 etc. the numeric type of data may
either be positive or negative
2. Alphabetic data : Alphabetic data consist of alphabetic
letters from A to Z , a to z and blank space. Like “IT Series”,
“Computer” etc.
3. Alphanumeric Data : alphanumeric data consist of
numeric digits (0-9), letters (A-Z) and all special characters
like +, %, #, $ etc.

Omid Adel
Data Types continue…
4. Image Data : this type of data includes charts, graphs,
pictures and drawing. This form of data is more
comprehensive. It can be transmitted as set of bit
5. Audio Data : sound is a representation of audio. Audio data
includes music or any type of sound.
6. Video data : video data is a set of full-motion image played
at high speed. Video is used to display action and
movements

Omid Adel
 Information : information is an organized and processed form
of data is called.
It is more meaningful than data and is used for making
decisions.
Data is used as input for the processing and information is the
output of this processing.

Data processing Information

Omid Adel
Metadata can be defined as data about data. It is used to
describe the properties and characteristics of some other data.
Means it describe the size, format and other characteristic of
data.
Example of Metadata

Field name Data types Length Description

Roll No Int 5 No null value

Name Nvarchar 30
Phone Nvarchar 10
Email address Varchar 15 Must contain @
and .

Omid Adel
File processing system is the first computer-based method to
handle business application. Many organization stored data in
files on tape or disk.
In file processing system each department in an organization
has its own set of files.
In file processing system the records in one file are not related
to the records in any other file

Omid Adel
Faculty Department Hostel

Keep Keep Keep


record record record

student student student

Omid Adel
1. Data Redundancy and inconsistency
2. Program Data dependency
3. Limited data sharing
4. Lengthy development times
5. Security problems
6. Program maintenance

Omid Adel
Redundancy : Redundancy means the duplication of same data
in several files. This redundancy causes higher storage.
Example :
 suppose there are two files “student” and “library”. The file
student contain the Roll No, Name, address and other detail of
student. The file library contain the Roll No and name of those
student how get the book from library the data of one student
appears in two files. This is called data Redundancy.

Omid Adel
Inconsistency : inconsistency means that two files may contain
different data about same person, student and organization etc.
Example :
Suppose that we have two files of student and library. If the
address of student is changed, it must be changed in both files.
There is a possibility that it is changed in the student file and not
in library file. The become inconsistent in this situation.

Omid Adel
In file processing system programs are developed according to a
particular file format.
If the format of file is changed it needs to bring changed in whole
program

3. Limited data sharing


In file processing system each application has its own private
files to use it.
Each user can access their own files and they have a little
opportunity to share data outside of their won application

Omid Adel
In file processing system each new application required that
the developer essentially start from beginning by designing new
file formats.
Because in file processing system we can not bring change in
our exist program or file format
If we want to bring some changes in our program we must
bring changes in the whole program and it take a lot time to
developed new file formats.

Omid Adel
The biggest problem in file processing system is security
In this type of system we can not apply any type of security on
our data. In some situation it required to provide different types
of access to data for different users
For example : the data entry operator should only be allowed to
enter data. The manager of an organization should be able to
access or delete the data completely. Such type of security option
are not available in file processing system

Omid Adel
The program developed in file processing system are difficult
to maintain.
Most of the budget may be spent on the maintenance of
program which is developed in file processing system.
Because its so difficult to developed new application

Omid Adel
Database is an organized collection of related data that is
stored in an efficient manner.
Organized : the world organized means that data is stored in
such away that the user can use this data easily.
Related : the word related means that a database is normally
created to store the data about a particular topic.
Efficient : the word efficient means that the user can search the
required data quickly.

Omid Adel
Database management system (DBMS) : a database
management system is a collection of program or software that
are used to create and maintain a database.
It is a general purpose software system that provides the
following facilities
1. It provide the facility to define the structure of database. The
user can specify data types, format and constraints for the
data to be stored in database
2. It provides the facility to store data on some storage medium
controlled by DBMS.

Omid Adel
3. It provides the facilities to insert, delete, update and retrieve
specific data to generate reports

Tables
 Table is the fundamental object of database structure the
basic purpose of a table is to store data.
 A table consist of rows and columns, the data in table can be
manipulated easily
ID Name Phone Address
1 Waheedullah 0799202020 Kabul, Afghanistan
2 Naqibullah 0777121212 Konar, Afghanistan

Omid Adel
Rows are the horizontal part of the table. It is a collection of
related fields
Each row contain a records of different person.

1 Waheedullah 0799202020 Kabul, Afghanistan


2 Naqibullah 0777121212 Kunar, Afghanistan

Columns/Field
Columns are the vertical part of the table
Waheedullah

Naqibullah

Abdullah

Omid Adel
1. Redundancy control :
 The data in database appears only once and is not duplicated.
The database approach does not eliminate redundancy, but it
enables the designer to control the type and amount of
redundancy
2. Data consistency :
 An important benefit of controlling redundancy is that the data is
consistent. If a data item appears only at one place, it is easy to
maintain. If it is required to update data, the updating is
performed at only one place. The change will automatically take
effect at all places where ever this data is used

Omid Adel
3. Data independence :
Database approach provides the facility of data independence. It
means that the data and the application programs are separate from
each other. It is possible to change data storage structures and
operation without changing the application programs.

4. Data sharing :
Once a database is developed, in can be used by several users in
organization. The database can also be shared by different
application. If a new application requires the same data, it can share
the existing database instead of developing it again.

Omid Adel
5. Reduced development time :
A database organize data more efficiently than a file processing
system. It is easier and faster to develop programs that use this data.
Many database management systems also provide several tools to
developed programs. so it reduces the overall time for developing
application.

6. Data Security :
Data security is the protection of the database from unauthorized
access. The database management system provides several procedure
to maintain data security.
It is required to provide different types of access permission to data
or different users

Omid Adel
7. Improved Backup and Recovery :
 One of the most important benefit of database is the backup and
recovery.
Means we can get easily the backup of our existence data in the table,
if our computer or other device become failure we can easily restore
our existence database backup with all data.
The modern DBMS provide facilities to minimize the amount of
processing that can be lost due to a failure.

Omid Adel
Disadvantage of Database
1. High cost of DBMS :
 A complete database management system is very large and
important software .
 It is expensive to purchase database management software.

2. Higher hardware cost :


 Database management systems are heavy software's. additional
memory and processing power may be required to run the
DBMS.
 It required more powerful hardware.

Omid Adel
Disadvantage of database…
3. Higher programming cost :
 DBMS is a complex software. The programmers need a lot of
knowledge of system to use it.
 An organization want to hires/recruitment experience database
programmers, it has to pay extra cost for this person
4. High conversion cost :
 The conversion of one system to another system is costly.
 Because each system has its own file formats. Different systems
has different formats to saved records
 The structure and data may also have to be modified according
to the requirements of DBMS.

Omid Adel
Disadvantage of database…
5. More chance of failure :
 In database management system (DBMS) all resources and
components are centralized.
 If any of these components fails, the whole systems stops. Because
all the records, data etc are located in one central device and all other
systems are access data from central device.

Omid Adel
Relationship of application program and DBMS

 Database application is developed by using both application


program and database management system. The application
program contain the user interface.
 User uses this interface for communicating with database
management system
 The application program is also called the front-end
 The database is known back-end
 The user can not use the database directly if they don’t have any
technical knowledge about database management system

Omid Adel
Relationship of application program and DBMS

Omid Adel
Range of database application
1. Personal Database :
 Personal database are designed to support one user. Means it is
specially designed for single user.
 The user may be using this database in desktop or laptop
computers, these computer may use a simple database
application in which the records of customers are stored.
 It is difficult to share personal database quickly with other
users in organization

Omid Adel
Range of database application…
2. Workgroup Database :
 Workgroup is the team of people who work on the same project
or application
 Workgroup normally consists of less than 25 people.
 The people in workgroup are connected with one another
through local area network (LAN). The database is stored on a
central computer called server.
 All members of workgroup can share this database with each
other

Omid Adel
Range of database application…
3. Department database :
 Functional unit within an organization is called department
 A department is larger than workgroup system it consist of 25 to
100 person and is responsible for a more range of function.
 It is specially designed to support the functions of department.
4.Enterprise database :
 An enterprise database is one whose scope is the entire
organization. Means a type of database that is specially designed
to support the function of whole organization or many
departments of an organization

Omid Adel
What roles do people take around a database system?

 1- Database designers
 2 - Application programs
 3 - End users
 4 - Database administrators

Omid Adel
Database designer
 Database designer gathering of information about the
application field.
 Analyze the collected requirements for database
 The database designer create physically design (ER) diagram
and conceptually (logically) design and implement the database
 The database designers are responsible to select DBMS. For
creation of database

Omid Adel
Application program
 Application program is a program that is used to send command
to the database management system
 These commands are sent to the database management system
through graphical user interface.
 The user interacts with application program and the application
program further interacts with the DBMS.
 It has graphical user interface (GUI) for the database

Omid Adel
End user
 End users are the people who will use the database when it is
finished
 Normally little technical knowledge required for end user to use
database

Omid Adel
Database administrators
 Database administrator is the most technical user. He is
responsible for managing the whole database system
 Database administrator managing the users accounts who can
access the database, Hardware resources, Backup and restore of
database
 Database administrator is responsible for database during its life
time

Omid Adel
Topic : Entity Relationship (E-R) Model

Omid Adel
Entity Relationship (E-R) Model
 An entity relationship (E-R) model is a detailed, logical
representation of the data for an organization or for a business
area
 The entity relationship (E-R) model consist of entities, the
relationships among those entities and the attributes of both the
entities and relationship.
 An entity relationship (E-R) model is also called Entity
relationship diagram or E-R diagrams which is graphical
representation of and E-R model.

Omid Adel
Element of E-R Model
 Entity relationship model or ( E-R Model) involve different types
of elements such us:
1 . Entity
2.Attribute
3. Relationship

Omid Adel
Elements of E-R Model …
1. Entity :
 An entity is a person, place, object, or event in the user
environment about which the organization want to maintain
data.
 For example the hospital system may include entity like patient ,
doctor etc.
 Some example of entity
 Person : Employ, Student, Doctor, Patient
 Place : Store, Country, Province
 Object : Machine, Building, Furniture
 Event : Purchase, Sale, Registration

Omid Adel
Elements of E-R Model …
1.Entity Type :
 An entity type is a collection of entities with same or common
properties or characteristic.
 Each entity type in E-R model is given a name, because the
name represent a collection of items.
 Entity type is always singular, and use capital letters for names
of entity types
 In an E-R diagram the entity name is placed inside the box
which representing the entity type

Omid Adel
Elements of E-R Model …
2. Entity Instance:
 An entity instance is a single member or occurrence of entity
type is called entity instance
 Each entity instance of an entity type has its own value for each
instance
 For example we have the Employ entity type in this employ entity
type the Ahmad is the entity instance ot that Employ entity type

Omid Adel
Types of Entity
1. Weak Entity :
 Weak entity is a type of entity whose existence depends of
some other entity. Means it can exist only if another entity exist
 A weak entity has no meaning in E-R diagram without the entity on
which it depends.
 It is also called child, dependent or subordinate entity
 In the E-R diagram we represent the weak entity as double – line
square

Omid Adel
Example of weak entity
birthdate
PersonID Name childNmae

PERSON Has CHILD

 In the above example CHILD is a weak entity, its existence is


depend on the existence of another entity

Omid Adel
Types of Entity…
2. Strong Entity :
 Strong entity is a type of entity whose existence does not
depends of some other entity. Means it can exist without the
existence of another entity
 Strong entity is also called parent, owner or dominant entity
 In the E-R diagram we represent the Strong entity as single– line
square

Omid Adel
Example of Strong entity
birthdate
PersonID Name childNmae

PERSON Has CHILD

 In the above example PERSON is a strong entity, which its


existence is does not depend on the existence of another entity

Omid Adel
Elements of E-R Model …
2.Attributes :
 An attribute is a property or characteristic of an entity type that
is interest to the organization
 In the naming attribute, we use an initial capital letter followed
by lower case letters
 If an attribute name consist of two words, we use an underscore
character to connect the words with each other
 For example we have the STUDENT entity type some attributes
are :
Student_ID , Name , Phone_Number , Home_Address etc.

Omid Adel
2.Example of attribute

Student_ID Name

Address STUDENT Phone_Number

Email

Omid Adel
Types of Attributes
1.Simple Attribute :
 Simple attribute is an attribute that cannot be subdivided into
smaller component
 Simple attribute is also called atomic attribute
 For example a student can have only one date of birth and gender

Birth_Date Gender

STUDENT

Omid Adel
Types of Attributes…
2. Composite Attribute :
 Composite Attribute is a type of attribute that can be divided
into smaller component
 For example the Address is an example of composite attribute
Province Zone Home_address

Address

STUDENT

Omid Adel
Types of Attributes…
3. Single Value Attribute :
 It is a type of attribute that may contain single value is called
single value attribute
4. Multi Value Attribute :
 It is a type of attribute that may contain two or more than two
value is called multi value attributes
 Multi value attribute is represented as double line oval
 For example : An employ can have two or more than two
university degree, an also its possible in an organization an
employ may have many skills

Omid Adel
Types of Attributes…
5. Derived attributes :
 Derived Attribute is a type of attribute that is not stored in the
database, but derived from another value
 The value of derived attribute can be calculated from another
related attribute values.
 Derived attribute is represented in E-R diagram in ellipse with a
dashed line

Omid Adel
Topic : Entity Relationship (E-R) Model
(Continue)

Omid Adel
Elements of E-R Model …
 Entity relationship ( E-R ) Model involve different types of
elements such us:
1 . Entity
2. Attribute
3. Relationship

Omid Adel
Element of E-R Model…

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

Omid Adel
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
Course_Id Course_Name
Id Name

TEACHER complete COURSE

Complet_Date

Omid Adel
Associative Entity
 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

Omid Adel
Degree of Relationship
 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

Omid Adel
1.Unary Relationship
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

EMPLOY TEACHER

manage Teach

Omid Adel
Binary Relationship
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

Omid Adel
Binary Relationship…
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 1
MANAGER manage BRANCH

 The above relationship means that one manager manage one


branch. Similarly, one branch is manage by one manager.

Omid Adel
One-to-One Example
A B

a1 b1

a2 b2

a3 b3

a4 b4

Omid Adel
One-to-One Relationship…
Example of One-to-One Relationship :
1 1
COUNTRY Has PRESIDENT

The above relationship means that one country has one president.
Similarly, one president of only one country
1 1
CHAIRMAN Run UNIVERSITY

The above relationship means that one chairman run only one
university. Similarly, one university is run by one chairman

Omid Adel
Binary Relationship…
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
PROVINCE Has DISTRICT

 The above relationship means that one province can have many
district, but one district is only belong to one province

Omid Adel
One-to-Many Example

A B
a1 b1

a2 b2

a3 b3

a4 b4

Omid Adel
Many-to-one Example

A B

a1

b1
a2

a3
b2
b2

a4

b3
a5

Omid Adel
Example of One-to-Many Relationship
1 M
FACULTY Has DEPARTMENT

the above relation means that one faculty can have many
departments, but one department is only belong to one faculty.
1 M

DEPARTMENT Work EMPLOY

the above relationship means that in one department can work


many employ, but one employ can only work on one department

Omid Adel
Binary Relationship…
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

STUDENT Study COURSE

 The above relationship means, that one student may study more
course, and one course may be studied by more students

Omid Adel
Many-to-Many Example
A B

a1 b1

a2 b2

a3
b3

a4 b4

Omid Adel
Example of Many-to-Many Relationship
EMPLOYEE Has SKILS

 The above relationship means that one employ learn many skills and one
skill can be learned by many employees.

READER Read BOOK

 The above relationship means that one reader may read many books and one
book may be read by one reader

Omid Adel
Ternary Relationship
3. Ternary Relationship :
 Ternary Relationship is a type of relationship which is
established between the instance of three entity types
Contract
MANAGER CLIENT

PROJECT
 The above relationship means that one or many manager with
one or many clients sign contract in one or many projects

Omid Adel
Example of Ternary Relationship

ANALYST Works_On PROGRAMMER

PROJECT

 The above relationship means that one or many analyst with one
or many programmers works on one or many projects

Omid Adel
Cardinality Constraints
 Cardinality constraints specifies the number of instance of one
entity that can (or must) be associated with each instance of
another entity.
 There are three types of symbols used to show cardinality
1. circle : It means that the minimum number of relationship
between each instance of first entity and instance of second
entity is zero. It is also called the optional relationship
2. line : it means that the minimum number of relationship
between each instance of first entity and instance of second
entity is one. It is also called mandatory relationship
3. Crows-foot : it means that many relationships between instance
of the first entity and instance of second entity
Omid Adel
Cardinality Constraints…
 Optional Relationship :
 It means that the minimum number of relationship between
each instance of first entity type and instance of second entity is
zero.
 It is called optional relationship.
 Mandatory Relationship :
 It means that the minimum number of relationship between
each instance of first entity type and instance of second entity
type is one.
 It is called mandatory relationship

Omid Adel
Cardinality Constraints…

Mandatory one

Mandatory Many

Optional one

Optional many
Omid Adel
Example : One-to-Many Relationship(Optional)

STUDENT BOOK

 The shape with STUDENT show that minimum cardinality


of STUDENT is zero and maximum is one. The shape with
BOOK shows that minimum cardinality is zero and
maximum cardinality is many
It means that one student can get zero or many books
and one book can get by one or no student

Omid Adel
Example : Many-to-One Relationship(Mandatory)

EMPLOYEE PROJECT

 In the employee section the minimum cardinality is one and


maximum is many, and in the project section the minimum and
maximum cardinality is one
 It means, that one or many employee may be working on one
project, but one employ must work on exactly one project

Omid Adel
Example : Many-to-Many Relationship(Optional)

STUDENT COURSE

The minimum cardinality on both side is zero and the


maximum cardinality on both side is many
It means, that one student can take many or no course
to study, similarly one course can be taken by many
students or no students.

Omid Adel
Notation Guide

• Entity Type

• Weak Entity Type

• Relationship Type

• Associative Entity

Omid Adel
Notation Guide…

• Attribute
_____
• Key Attribute

• Multi value Attribute

• Derived Attribute

• Composite Attribute

Omid Adel
Keys
 A key is an attribute or set of attributes that uniquely identify a
row in a relation.
 The key are defined in table to access or sequence the stored data
quickly.
 They are also used to create relationship between different tables
1.Super key
2.Candidate key
3.Primary key
4.Alternate key
5.Composite key
6.Foreign key
Omid Adel
Super key
1.Super key :
 Super key is an attribute or combination of attributes in a
relation that identifies a row uniquely within relation.
 Any combination of attributes with the super key is also a super
key. It means any attribute or set of attributes combined with
super key is also become a super key.
 A STUDENT entity with different attributes such us :
 RegID, Name, Father Name, Class, Address, etc
 RegID : super key
 {RegID, Name} : super key
 {RegID, Class} : super key

Omid Adel
Candidate Key
2. Candidate Key :
 Candidate key is a super key that contains no extra attribute.
 A super key with single attribute which uniquely identify a row
in relation is as well as candidate key.
 A STUDENT entity with different attributes such us :
 RegID, Name, Father Name, Class, Address
 {RegID} : Super key and candidate key
 {RegID, Class} : Super key but not candidate key because it
contains an extra field of Class.

Omid Adel
Primary Key
3. Primary Key :
 Primary key is a candidate key that is selected by the database
designer to identify a row uniquely in a relation or table.
 A relation may contain many candidate keys, when the designer
selects one of them to identify a row in the relation, it become a
primary key.
 Some important points about primary key :
1. A relation can have only one primary key.
2. Each value in primary key attribute must be unique.
3. primary key cannot contain null values.

Omid Adel
Alternate Key
4. Alternate Key :
 The candidate keys that are not selected as primary key are
known as alternate key.
 Suppose student relation contain different attributes such us :
 RegNo, RollNo, Name, Class, Address etc. the attributes of
RegNo and RollNo can be used to uniquely identify each student
in table.
 In this situation the designer select one of them as primary key
which is most important to organization.

Omid Adel
Composite Key
5. Composite Key :
 A primary key that consist of two or more attributes is known as
composite key.
 Sometimes its required to select composite primary key to
identify a row uniquely in relation.
 for example : each student must pay their fee only once in per
months. In this situation we must select composite primary key
to solve this problems. We select the student ID and months us
composite primary key.

Omid Adel
Foreign Key
6. Foreign Key :
 Foreign key is an attribute or set of attributes in a relation whose
values match a primary key in another relation.
 The relation in which foreign key is created is known as
dependent or child Table
 The relation to which the foreign key refers is known as parent
Table.
 A relation is also contain many foreign keys.

Omid Adel
Example of foreign key
RollNo Name Phone No Address
1 Ahmad 0799202020 Kabul
2 Mahmood 0777202020 Khost
3 Khan 0788202020 Mazar
4 Ali 0700202020 Kundoz

SubID Subject Marks RollNo


1 English 50 2
2 C++ 70 4
3 Database 65 1
4 English 80 2
Omid Adel
Topic :Relational Model

Omid Adel
Database Design using E-R model
1. Converting Entities into Relation
2. Converting Composite Attributes
3. Converting Multi-value Attributes
4. Converting Weak Entities
5. Converting Binary Relationship
5.1 Binary one-to-one Relationship
5.2 Binary one-to-many Relationship
5.3 Binary many-to-many Relationship
6. Ternary Relationship
7. Super Type / Subtype Relationship

Omid Adel
Database Design using E-R model
 E-R model represents different things as entities
 The connections among different entities are represented by
relationships.
 These entities and relationships can transformed into relational
model.
 This model can be used to design the database using relational
model

Omid Adel
Converting Entities into Relation
 The process of converting entities into relation is very simple
 The name of entity become the name of relation (table) and
attributes of entity become the fields (columns) of relation.
 the following example explains the process of converting an
entity into relation.

Name Phone_No

Emp_id BirthDate

EMPLOYEE

Omid Adel
Converting Entities into Relation
EMPLOYEE
Emp_id Name Phone_No BirthDate

 In the above example, EMPLOYEE entity is converted into


relation. The attributes of entity are fields of the relation.
 The data model describes Emp_ID as an identifier and is
underlined.
 The above relation is using Emp_ID as primary key for the
relation.

Omid Adel
Converting Composite Attributes
 If an entity contains composite attributes, each part of the
attributes is represented by a separate field in the relation.

Zone
Province Location

Name
Address
Phone_No

Emp_ID

EMPLOYEE
EMPLOYEE
Emp_ID Name Province Zone Location Phone_No

Omid Adel
Converting Multi-Value Attributes
 The attribute is represented in a separate relation if an entity
contains multi-value attributes
 The following E-R model contains a multi-value attribute Skills.
 This attribute is represented in a second relation.

Name Phone_No
Skill

BirthDate
Emp_ID

EMPLOYEE

Omid Adel
Converting Multi-Value Attributes
EMPLOYEE
EmpID Name Phone_No BirthDate

SKILL
Skill EmpID

 The second relation SKILL is using EmpID and Skill as


composite key , It may contain many rows.
 Each row will contain a single skill of the employee

Omid Adel
Converting Weak Entities
 Weak entity does not exist independently. It depends on the
existence of another entity known as identifying owner.
 When we convert weak entity into relation, first of all a relation
for the identifying owner is created.
 A separate relation is created for each weak entity and attributes
of weak entity become the fields of the relation.
 The weak entity relation is connected with the identifying
relation.
 The primary key of identifying relation is used as foreign key in
the weak entity relation

Omid Adel
Converting Weak Entities
ChildName BirthDate
PersonID Name

PERSON Has CHILD

PERSON
PersonID Name

CHILD
ChildName BirthDate PersonID

Omid Adel
Converting Binary Relationship
 Binary One-to-One Relationship:
 One-to-One relationship of E-R model is represented in
relations by performing the following two steps.
1. Create a relation for each of the two entity types participating in
the relationship
2. Include the primary key of the first relation as a foreign key in
the second relation.

Omid Adel
Binary One-to-One Relationship
Name DepID
Email DepName
MangID

Control DEPARTMENT
MANAGER

MANAGER
MangID Name Email

DEPARTMENT
DepID DepName MangID

Omid Adel
Converting Binary Relationship
 Binary One-to-Many Relationship:
 One-to-Many Relationship of E-R model is represented in
relation by performing the following two steps.
1. Create a relation for each of the two entity types participating in
the relationship.
2. include the primary key of the entity on one-side of the
relationship as a foreign key in the relation that is on the many
side of the relationship.

Omid Adel
Name PlayerID
Province Name
TeamID

TEAM Play PLAYER

TEAM
TeamID Name Province

PLAYER
PlayerID Name TeamID

Omid Adel
Converting Binary Relationship
 Binary Many-to-Many Relationship:
 Many-to-Many relationship of E-R model is represented in
relations by performing the following two steps.
1. Create two relations A and B for each of two entity types that
participating in the relationship.
2. Create another relation C that contains the primary key of both
A and B relation as foreign key.

Omid Adel
Name CourseID
Address Name
StudID

STUDENT admission COURSE

STUDENT
StudID Name Address

STUDENT_COURSE
CourseID StudID

COURSE
CourseID Name

Omid Adel
Converting Ternary Relationship
 Ternary relationship exist between the instance of three entity
types.
 Ternary relationship of E-R model is represented in relations by
performing the following two steps.
1. Create a relation for each entity type participating in the
relationship.
2. Create new relation to represent the link between three entity.
The primary key of new relation consist of primary keys of three
entities in the relationship. The attributes of associative entity
type become attributes of the new relation.

Omid Adel
Example of Ternary Relationship
SupID Name Quantity ProjID Detail

SUPPLIER Supply PROJECT

PART

PartID Name

Omid Adel
Converting Ternary Relationship
SUPPLIER
SupID Name

PROJECT
ProjID Detail

PART
PartID Name

SUPPLY_PRJECT_PART
SupID ProjID PartID Quantity

Omid Adel
Super Type/Subtype Relationship
 Super Type / Subtype relationship of E-R model is represented in
relations by performing the following steps.
1. Create a separate relation for super type and for each subtype.
2. The relation for super type consist of the attributes which are
common in all members. Assign a primary to the super type
relation.
3. The relation for each subtype consist of the attributes, which are
unique to that particular subtype. The primary key of the
subtype will be similar to the primary key of the super type.

Omid Adel
Address
Name

Email
PersoneID
PERSONE

STUDENT EMPLOYEE

Salary
Roll No

Disignation
Class

Omid Adel
Converting Super Type/Subtype Relationship
PERSON
PersonID Name Address Email

STUDENT
StudentID Roll NO Class

EMPLOYEE
EmployeeID Disignation Salary

Omid Adel
Thanks for your attention
Any Questions
&
Suggestions

Omid Adel

You might also like