Professional Documents
Culture Documents
Relational Database Design - : Mapping ERD To Relational
Relational Database Design - : Mapping ERD To Relational
Entity Relation
Entity Name Relation Name
Simple Attribute Attribute of the relation
Entity Identifier Primary key of relation
Composite Attribute Set of component attributes
Multi-valued Attribute New relation with PK
First Name
Emp No
Mid Initials Location
NID Emp Name
Last Name Dept Name
Address
Phone
Dept No
Department
Employee
Salary Employees
Employee (Emp_No, NID, Address,
Gender
Salary, Gender, DOB,
DOB
First_Name, Mid_Initials, Last_Name)
Department(Dept_No, Dept_Name, Phone)
FK
Dept_Location(Dept_No, Location)
2. Map Weak Entities
Each weak entity type in an ERD is transformed into a
relation.
Entity Relation
Entity Name Relation Name
Simple attribute Attribute of the relation
Owner entity identifier Foreign key attribute
Entity identifier (partial) Composite key together
with PK of owner as FK
Composite attribute Set of component attributes
Multi-valued attribute New relation with PK
Emp No
Employee
has
Start d
Employee Department
Salary manage
Employees
Gender
DOB Employee (Emp_No, NID, Address,
Salary, Gender, DOB, First_Name,
Mid_Initials, Last_Name, Dept_No) FK
Department(Dept_No, Dept_Name, Phone , Manager NN
Start_D)
Map Binary One-to-Many Relationships
Department(Dept_No,
Department
Dept_Name, Phone)
Employees
control
Proj No
Project (Proj_ No, Proj_Name,
Location , Dept_No) Project
FK
Location Proj Name
Map Binary Many-to-Many Relationships
Functional dependency:
A constraint between two attributes or two sets of
attributes.
• Normalization is based on the analysis of
functional dependencies.
• The functional dependency of B on A is represented
by an arrow: A B i.e B is dependent on A.
EX: ENO Name, Address, Birth date (Employee)
VID Make, Model, Colour (Vehicle)
ISBN Title, First Author (Book)
• In the above example EMPNO is the Primary Key .
With the help of the primary key we identify the
record uniquely.
• So, EMPNO is called key attribute or determinant
attribute and rest of the attributes i.e Name, Address,
Birth date are called non-key attributes.
• So the attribute on the left hand side of the arrow is
called Key attribute and on the right hand side of
arrow are called non-key attributes.
• Therefore non-key attributes are functionally
dependent on key attribute.
• So each and every relation must have at least one key
attribute.
• 4.3 Normalization:
• E-R diagrams help use with overall design, but a good
conceptual design does not necessarily lead to a good
table structures.
• Tables are the basic building blocks of the database in
RDBMS.
• We wish to avoid data anomalies/redundancies by
controlling the table structure.
• Data redundancy :
• Storing data multiple times.
Too much data redundancy causes problems like
which value is correct?
Logical Database Design -
Normalisation
Normalisation
Non-Redundant,
Consistent and
Inter-Dependent Relations
Normalisation
2. DELETE PROBLEM
loose information of part P7 if we cancel purchase
order 115 (i.e. Delete PO-PART for Part No P7)
3. UPDATE PROBLEM:
to change description of Part P3 we need to change
every tuple in PO-PART containing Part No P3
Second Normal Form - 2NF
A relation is in 2NF if it is in 1NF and every
non-key attribute is dependent on the
whole key
2. DELETE PROBLEM
loose information of supplier 100 if we cancel
purchase order 116 (i.e. Delete PO for Supplier No
100)
3. UPDATE PROBLEM
to change name of Supplier 222 we need to change
every tuple in PO containing Supplier No 222
Third Normal Form - 3NF
A relation is in 3NF if it is in 2NF and each
non-key attribute is only dependent on
the whole key, and not dependent on any
non-key attribute.
PO
SUPPLIER
PO- PO-DATE EMP- SUPP
NO CODE -NO SUPP SUPP-
-NO NAME
111 01012001 M2 222
112 01012001 S3 105 100 LM Centre
113 02012001 S1 111 105 I Hardware
114 02012001 M2 150 111 BC Trading
115 03012001 S1 222 150 DO Service
116 04012001 S1 100 222 AC Stores
Purchase Order Relations in 3NF
SUPPLIER SUP SUPP-
P-NO NAME
PART PO-PART
222 AC Stores
105 I Hardware PAR PART- PO- PAR PART
111 BC Trading T-NO DESC NO T-NO -QTY
150 DO Service P1 Nut 111 P1 10
222 AC Stores P2 Bolt 111 P2 5
100 LM Centre P3 Nail 111 P3 3
PO P5 Screw 111 P5 6
PO- PO- EMP- SUP P6 Plug 112 P2 2
NO DATE CODE P-NO P7 Pin 112 P5 1
111 01012001 M2 222 P8 Fuse 113 P1 3
112 01012001 S3 105 113 P3 4
113 02012001 S1 111 114 P6 5
114 02012001 M2 150 115 P7 8
115 03012001 S1 222 116 P8 2
116 04012001 S1 100
• Advantages of Normalization:
• Normalization provides numerous benefits to a
database. Some of the major benefits include the
following:
• Greater overall database organization.
• Reduction of redundant data.
• Saves the disk space and simplify the structure of
data.
• Data consistency within the database.
• A much more flexible database design.
• A better handle on database security.
• Disadvantages of Normalization:
• Requires much more CPU, memory, and I/O
to process thus normalized data gives reduced
database performance.
• Queries run slower because of the joins.
• Poorly-written query can bring the database
down
• Maintenance overhead:
• The higher the level of normalization, the
greater the number of tables in the database.
Further Normalization
• BCNF or Boyce–Codd Normal form
• 4th Normal form
• 5th Normal form
In a normal situation normalization up-to 3NF is quite
sufficient.Certain relations may even be de-normalized on
account of efficiency. The Normalizations which are
discussed next are not practically enforced most of the
time.
• But a relation in 3NF does not guarantee that all
anomalies have been removed, hence the additional
normalizations.
• Lossless Joins:
A relation schema ‘R’ can be decomposed into a
collection of relation schemas to eliminate some of
the anomalies contained in the original relation
schema ‘R’.
• Any such decomposition requires the information
contained in the original relation to be maintained i.e
the join of the decomposed relation should give the
same set of tuples as the original relation then such a
decomposition is called as lossless join
decomposition.
• The lossless join decomposition enables any
relation to be recovered from the
decompositions by a series of natural joins.
• Such decomposition contains the same data as
the original relation.
• Dependency Preserving Dependency:
• If R is decomposed into X, Y and Z, and we
enforce the FDs that hold on X, on Y and on
Z, then all FDs that were given to hold on R
must be hold.