Database Management System and ER Modelling
Database Management System and ER Modelling
and
ER Modelling
Keshan
Consultant/Lecturer at NIBM
MBA in MOT (Gold Medal & Top of the Batch) University of Moratuwa
BSc in MIS (First Class Honours with Two Gold Medals) University College of Dublin
Work Hard!!!
Study Hard!!!!
Target A+ for each Subject!!!!
Become a Champion and Make yourself
Proud!!!!
Introduction
• A database is an integrated collection of logically related records
and files.
Savings
Savings
Account Account
Data Programs
Files
Example
Programs to print a student's
Student
transcript and to enter new
Details
grades into the
+
file are implemented as part of
Student
the application.
Grades
User 1: Grade
Reporting Officer
• Data inconsistency
The various copies of the same data may no longer agree.
• Data isolation.
Database Processing
• All applications interface with the same data in a central database
Checking
Account
Database Programs
Auto
Management Loan
Database
System Programs Savings
Account
Programs
Why DBMS?
a) Sharing of data
b) Controlling of Redundancy
A multi-user DBMS allows multiple users to access the database at the
same time.
c) Security restrictions
User access to the Database is restricted by account numbers and passwords.
d) Backup and recovery
A DBMS must provide facilities for recovering from hardware and software
failures.
e) Flexibility
Allows changes to the structure of the database without effecting most of the
application programs.
f) Enforcing integrity constraints (accuracy of data)
Attributes:
Each entity has properties called “Attributes” that describes the entity.
A person has attributes like : Name, height, weight, nationality
A car has attributes like : Color, model, make
Relationships :
A relationship is an association (connection) between two or more
entities.
2. Weak entity
Entity types that do not have key attributes of their own are called
weak entities.
Key attributes (Primary key)
An Entity can be uniquely identified by a key attribute.
Eg: EmpNo, NIC
A weak entity has a partial key which can be used to distinguished two
weak entities belongs to the same owner entity.
Eg : Consider the entity : DEPENDENT
It has attributes : Dependent name, DOB, Relationship
If we take two entries of the dependent entity it is possible to have same values for the above 3
attributes.
Therefore to separate two weak entities the key attribute of the weak entity is develop with the
help of the owner (strong) entity.
The full primary key of a weak entity is the combination of Empno & Dependent name.
Types of Attributes
2. Composite Attributes
Composite attributes can divide in to more basic attributes.
House no
4. Stored attributes
An attribute whose value is fixed and cannot change.
Eg: Date of Birth, NIC
5. Derived attributes
An attribute whose value can be calculated from a stored attribute.
Eg: Age can be calculate using DOB
Relationship Constraints
A relationship usually has certain constraints that limits the
possible combinations of entities that may participate in
relationship instance. There are two types of relationship
constraints.
• Cardinality ratio
• Participation
Cardinality Ratio
The cardinality ratio specifies the number of relationship instances
that an entity can participate.
Nimal Accounts
Sunil Admin
Mala HR
Amila Sales
1:1
E1
HR
E2
Sales E3
E4
E5
1:m
Many-to-many (m:n)
An entity in A is associated with a number of entities in B, and
an entity in B can be associated with any number of entities in
A.
E1 P1
E2 P2
P3
E3
P4
E4
m:n
Normalization
27
Example 01
Department table
Dept_1
Dno Dname ManagerEno
Dept_2
Dno Dloc
Example 02
30
After Normalization
Emp_proj
Project Employee_Project
Eno Ename
Pno Hours
100 Nimal 4 100 Eno Ename PNo Hours
100 Nimal 7 40
100 Nimal 2 150 Employee
200 Sunil 2 100
Eno Ename
200 Sunil 1 55
Emp_Proj
key attribute 32
Example:
33
Items
Invno Itemno Iname Invdate Qty
Emp_proj
Eno Pno Hours Ename Pname Ploc
Supplier_Project
Project
Pno Pname
Third Normal Form (3NF)
Transitive Dependency
(X ->Z)
Condition A:
Condition B:
X is a super key of R
OR
A is a prime attribute of R (when X is not a super key)
Super Key
• A super key is a set of one or more attributes (columns), which can uniquely
identify a row in a table. Often we get confused between super key and
candidate key.
• Candidate keys are selected from the set of super keys, the only thing we take
care while selecting candidate key is: It should not have any redundant
attribute. That’s the reason they are also termed as minimal super key.
Super keys: The above table has following super keys. All of the following sets of super key are able to
uniquely identify a row of the employee table.
{NIC}
{Employee_Number}
{NIC, Employee_Number}
{NIC, Emp_Name}
{Employee_Number, Emp_Name}
{NIC, Employee_Number, Emp_Name}
Candidate Keys: A candidate key is a minimal super key with no redundant attributes. The following two set
of super keys are chosen from the above sets as there are no redundant attributes in these sets.
{NIC}
{Employee_Number}
Only these two sets are candidate keys as all other sets are having redundant attributes that are not
necessary for unique identification.
Example 1
Consider the relation Supplier = {Sno, Pno, Sname, City, Status,
Pname, Qty} and the functional dependencies:
{Sno, Pno} -> {Qty}
{Sno} -> {Sname, City}
{Pno} -> {Pname}
{City} ->{Status}
Project City
Consider the relation which has attributes that hold schedules of courses and sections at a University.
R = { Courseno, Secno, Dept, Credithours, Clevel, Lectno, Sem, year, Days_hours, Roomno,
No_of_St}. Suppose that the following functional dependencies hold on R:
• {Courseno} -> {Dept, Credithours, Clevel}