You are on page 1of 53

Database Management System

UNIT-I
INTRODUCTION AND ER MODEL

M. Muni Babu
M.Tech, (Ph.D)
Assistant Professor
Dept. of CSE
IIIT R K Valley, RGUKT
Idupulapaya
TOPICS
• History of Database

• Introduction to Database Systems

• File System vs. Database Systems

• Database System Structure

• Views of data in a Database System

• Data Models and Database Languages

• Introduction to Entity-Relationship data Model

• Elements of an ER Model

• Constructing ER diagrams

• Modelling of constraints

• Reduction of ER diagrams to tables


TOPICS
• History of Database

• Introduction to Database Systems

• File System vs. Database Systems

• Database System Structure

• Views of data in a Database System

• Data Models and Database Languages

• Introduction to Entity-Relationship data Model

• Elements of an ER Model

• Constructing ER diagrams

• Modelling of constraints

• Reduction of ER diagrams to tables


Entity Relationship Diagram

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Basic Concepts and Notations
on
Entity Relationship Diagram

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


What is an ERD?

• An Entity Relationship Diagram (ERD) is a graphical


representation of an organization’s data storage
requirements

• ERDs are abstractions of the real world, which


simplify the problem to be solved while retaining its
essential features

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Why ERD?
• Entity relationship diagrams are used to
– Identify the data that must be captured, stored and retrieved
in order to support the activities performed by an
organization

– A major data modeling tool and help to organize the data in


the project into entities and define the relationship between
entities

– It enables the analyst to produce a good database structure


so that the data can be stored and retrieved in a most
efficient manner

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Definitions
• An entity is an object in the miniworld.
• An attribute of an entity can have a value from a value set
(domain)
• Each entity belongs to some one entity type s.t. entities in one
entity type have the same attributes (so each entity type is a set
of similar entities).
• A key attribute of an entity type is one whose value uniquely
identifies an entity of that type.
• A combination of attributes may form a composite key.
• If there is no applicable value for an attribute that attribute is set
to a null value.

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


ER Diagram – Symbols

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


ER Diagram – Symbols

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


M. Muni Babu,, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT
Composition of ERD

• Entity relationship diagrams have three


components

– Entities

– Attributes

– Relationships

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Components of ERD

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Types of Attributes
• Simple attribute − Simple attributes are atomic values, which cannot be
divided further. For example, a student's phone number is an atomic value of 10
digits.
• Composite attribute − Composite attributes are made of more than one simple
attribute. For example, a student's complete name may have first_name and
last_name.
• Derived attribute − Derived attributes are the attributes that do not exist in the
physical database, but their values are derived from other attributes present in
the database. For example, average_salary in a department should not be saved
directly in the database, instead it can be derived. For another example, age can
be derived from data_of_birth.
• Single-value attribute − Single-value attributes contain single value. For
example − Social_Security_Number.
• Multi-value attribute − Multi-value attributes may contain more than one
values. For example, a person can have more than one phone number,
email_address, etc.

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Entity-Set and Keys
• Key is an attribute or collection of attributes that uniquely
identifies an entity among entity set.
• For example, the roll_number of a student makes him/her
identifiable among students.

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Entity-Set and Keys
• Key is an attribute or collection of attributes that uniquely
identifies an entity among entity set.
• For example, the roll_number of a student makes him/her
identifiable among students.
• Super Key − A set of attributes (one or more) that collectively
identifies an entity in an entity set.
• Candidate Key − A minimal super key is called a candidate key.
An entity set may have more than one candidate key.
• Primary Key − A primary key is one of the candidate keys
chosen by the database designer to uniquely identify the entity set.

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Entity-Set and Keys

• Primary Key: It is the first key which is used to identify one and only one instance of an
entity uniquely.
• Candidate Key: A candidate key is an attribute or set of an attribute which can uniquely
identify a tuple.
•The remaining attributes except for primary key are considered as a candidate key. The
candidate keys are as strong as the primary key.
•Super key: is a set of an attribute which can uniquely identify a tuple. Super key is a superset
of a candidate key.
•Foreign keys are the column of the table which is used to point to the primary key of another
table.
M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT
Types of Attributes
• These attribute types can come together in a way like −
• Simple single-valued attributes
• Simple multi-valued attributes
• Composite single-valued attributes
• Composite multi-valued attributes

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


ERD Methodology
10 basic steps
1. Identify entities
2. Find relationship
3. Draw rough ERD
4. Fill in cardinality
5. Define Primary keys(s)
6. Draw key-based ERD
7. Identify attributes
8. Map attributes
9. Draw fully attributes
10. Check results

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


A Simple Example
A company has several departments.
Each department has a supervisor and at least one employee.
Employees must be assigned to at least one, but possibly more
departments.
At least one employee is assigned to a project, but an
employee may be on vacation and not assigned to any
projects.
The important data fields are the names of the departments,
projects, supervisors, and employees, as well as, the
supervisor numbers, employee numbers and project numbers.

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Entity in ERD

• Entities
– An entity is anything real or abstract about which we want to store data.
In short, anything, which an organization needs to store data about

– Entity types fall into five classes


• Roles
e.g. Employee, Student
• Events
e.g. Payment, Borrow
• Locations
e.g. Campus, City
• Tangible things or concepts
e.g. Department, Book

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Representation Entity

• Entities
– Entities are represented on the diagram by labeled boxes

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Entity Sub-type

• Entities
– Sometimes it is useful to generalize a group of entities

Example
CAR, SHIP and AEROPLANE all are type of VEHICLE

Vehicle

Car Ship Aeroplane

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Attributes in ERD

• Attributes
– Entities are further described by their attributes (also called data
elements)

– Theses are the smallest units of data that can be described in a


meaningful manner

Example: An EMPLOYEE entity may the following attributes

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


ERD Methodology
10 basic steps
1. Identify entities
2. Find relationship
3. Draw rough ERD
4. Fill in cardinality
5. Define Primary keys(s)
6. Draw key-based ERD
7. Identify attributes
8. Map attributes
9. Draw fully attributes
10. Check results

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Relationships in ERD

• Relationships
– A data relationship is a natural association that exist
between one or more entities

Example
EMPLOYEE works in DEPARTMENT
EQUIPMENT is allocated to PROJECT
ESTEEM is a type of CAR

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


One-to-one Relationships

• Three types of relationship exist between two


different entities

• It is also called the cardinality (the number of


occurrences of one entity for a single occurrence of
the related entity)

– One-to-one relationship

– One-to-many relationship

– Many-to-many relationship

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


One-to-one Relationships
• This type of relationship takes place when a single occurrence
of an entity is related to just one occurrence of a second entity
Example:
PERSON owns a CAR
CAR is owned by a PERSON

Person Person

owns
own by

Car Car

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


One-to-many Relationships
• This type of relationship takes place when a single occurrence
of an entity is related to many occurrence of a second entity
Example:
DEPARTMENT has EMPLOYEE
EMPLOYEE works in DEPARMENT
Department Department

has
works in

Employee Employee

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Many-to-many Relationships

• This type of relationship takes place when many occurrence of


an entity are related to many occurrence of a second entity
Example:
STAFF work in PROJECT
PROJECT assigned to STAFF
Staff Staff

works in
assigned to

Project Project

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Recursive Relationships

• Relationship can exist between different occurrences of the


same type of entity
Example:
EMPLOYEE manager EMPLOYEE
NETWORK makes NETWORK

Employee Network

manager
makes

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Entity Relationship Diagram
Methodology

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


ERD Methodology

10 basic steps
1. Identify entities
2. Find relationship
3. Draw rough ERD
4. Fill in cardinality
5. Define Primary keys(s)
6. Draw key-based ERD
7. Identify attributes
8. Map attributes
9. Draw fully attributes
10. Check results

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


A Simple Example
A company has several departments.
Each department has a supervisor and at least one employee.
Employees must be assigned to at least one, but possibly more
departments.
At least one employee is assigned to a project, but an
employee may be on vacation and not assigned to any
projects.
The important data fields are the names of the departments,
projects, supervisors, and employees, as well as, the
supervisor numbers, employee numbers and project numbers.

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


1. Identify Entities

Objective: Identify the roles, events, locations, tangible things or concepts


about which the end-user want to store data

A company has several departments.


Each department has a supervisor and at least one employee. Employees
must be assigned to at least one, but possibly more departments.
At least one employee is assigned to a project, but an employee may be on
vacation and not assigned to any projects.
The important data fields are the names of the departments, projects,
supervisors, and employees, as well as, the supervisor numbers, employee
numbers and project numbers.

Note: One tempted to make company an entity, but it is a false entity because it has only
one instance in this problem. True entities must have more than one instance.

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


2. Find Relationships
Objective: Find the natural association between pair of entities using a relation
ship matrix

A company has several departments.


Each department has a supervisor and at least one employee. Employees must be
assigned to at least one, but possibly more departments.
At least one employee is assigned to a project, but an employee may be on
vacation and not assigned to any projects.

Department Employee Supervisor Project


Department is assigned has
Employee belongs to works on
Supervisor manages
Project uses

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


3. Draw Rough ERD
Objective: Put entities in rectangles and relationships on line segments
connecting the entities

Department Employee Supervisor Project


Department is assigned has
Employee belongs to works on
Supervisor manages
Project uses

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


4. Fill in Cardinality
Objective: Determine the number of occurrences of one entity for a single
occurrence of the related entity
A company has several departments.
Each department has a supervisor and at least one employee. Employees must be assigned
to at least one, but possibly more departments.
At least one employee is assigned to a project, but an employee may be on vacation and
not assigned to any projects.

From the description of the problem:


• Each Department has exactly one Supervisor
• A Supervisor is in charge of one and only one Department
• Each Department is assigned to at least one Employee
• Each Employee works for at least one Department
• Each Project has at least one Employee working on it
• An Employee is assigned to 0 or more project

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


4. Fill in Cardinality
From the description of the problem:
• Each Department has exactly one Supervisor
• A Supervisor is in charge of one and only one Department
• Each Department is assigned to at least one Employee
• Each Employee works for at least one Department
• Each Project has at least one Employee working on it
• An Employee is assigned to 0 or more project

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


5. Define Primary Keys
A company has several departments.
Each department has a supervisor and at least one employee. Employees must be assigned
to at least one, but possibly more departments.
At least one employee is assigned to a project, but an employee may be on vacation and
not assigned to any projects.
The important data fields are the names of the departments, projects, supervisors, and
employees, as well as, the supervisor numbers, employee numbers and project numbers.

The Primary keys are


• Department name
• Supervisor number
• Employee number
• Project number

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


6. Draw Key-based ERD

Objective: Eliminate many-to-many relationship and include primary and


foreign key in each entity

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


6. Draw Key-based ERD

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


7. Identify Attributes

Objective: Name the information details (fields), which are essential to the
system under development

The only attributes indicated are the names of


A company has several departments.
Each department has a supervisor and at least one employee.
Employees must be assigned to at least one, but possibly more
departments.
At least one employee is assigned to a project, but an employee
may be on vacation and not assigned to any projects.
The important data fields are the names of the departments,
projects, supervisors, and employees, as well as, the supervisor
numbers, employee numbers and project numbers.

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


8. Map Attributes

Objective: For each attribute, match it with exactly one entity that it describes

Attribute Entity
Department Name Department
Employee Number Employee
Employee Name Employee
Supervisor Number Supervisor
Supervisor Name Supervisor
Project Name Project
Project Number Project

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


9. Draw Fully Attributed ERD

Objective: Adjust the ERD from Step 6 to account for entities or relationships
discovered in Step 8.

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


9. Draw Fully Attributed ERD

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


10. Draw Fully Attributed ERD

Objective: Does the final ERD accurately depict the system data?

The Final ERD appears to model the data in this system well.

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Data Dictionary Sample
An example for a Banking System

Middle Name

First Name Last Name

Name
PAN Account No Account Type
Transaction No Date

Customer No

Gender
Customer Transaction Account

Address
Telephone TType TP Account
Customer No Balance
Amount
Account No

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Data Dictionary Sample
An example for a Banking System

• Stored entries of the corresponding DD (Account)

Account = {@AccountNo + AccountType + Balance + CustomerNo}


/* Storing balance information of an account */

AccountNo = 9(10) /*Unique bank account number */

AccountType = [Savings, Current, Recurring, STD]

Balance = Float /* Precise up to decimal points */

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Data Dictionary Sample
An example for a Banking System
• Stored entries of the corresponding DD (Customer)
Customer = {@CustomerNo + Name + Gender + PAN + Address + Telephone }
/* Customer personal data */
CustmerNo = 9(8) /* Unique customer identity number */
Name = FirstName + (MiddleName) + LastName
FirstName = {Characters, length : 18}
LastName = {Characters, length : 18}
MiddleName = {Characters, length : 18}

Characters = {A-Z, a-z,0-9,’,-}


PAN = X(10) /*Personal Account Number */
Gender = [Male, Female]
Address = /* Customer address, Length: 60 */
Telephone = 9(10) /* Customer’s telephone number */

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Data Dictionary Sample
An example for a Banking System
• Stored entries of the corresponding DD (Transaction)

Transaction = {@TransactionNo + Date + TType + Amount + (TPAccount) }


/* Transaction record of each banking */
TransactionNo = 9(12) /* A unique transaction number */
TType = [Deposit, Withdrwal, Transfer] /* Transaction Type */
TPAccount = AccountNo /* Third party account involved in a transaction */
Balance = Float /* Precise up to decimal points */
Date = /* Format : dd/mm/yyyy */

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


Problems to Ponder

• Manual data dictionary vs. automatic data


dictionary (in CASE)

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT


QUERIES……….. ???

END

M. Muni Babu, Assistant Professor, Dept. of CSE, IIIT R K Valley, RGUKT

You might also like