Professional Documents
Culture Documents
During Data Design, inputs from Data Modelling - Entity Relationship Diagram
(ERD) will also help arrive at the normalized tables. Let us try and understand
this concept with the help of an example. Consider the ERD given below.
Fig 1. ERD showing the relationship between Student, Course and Instructor
The above diagram shows 3 entities – Student, Course and Instructor. Entities,
as we know, always have data associated with it and Entities are derived from
the Datastores in Data Flow Diagram (DFD). Hence Entity represents data that is
to be stored for future use and the relationships shown in ERD should finally map
to database table relationship during Data Design or Normalization.
Now let us try and understand the Cardinality representation in any ERD. We
represent Cardinality as One – One, One – Many or Many – Many relationships.
So while creating the Database tables from this ERD, we should understand
there should be minimum 2 tables – one for Customer data and the other for
Holiday Pass data. The next is representing the relationship. The relationship
shown in Fig 2 is a One – One relationship between Customer and Holiday Pass.
The primary data or key of one table should be added as foreign key in the other
table to complete the relationship.
So we are to represent Customer table as
representing the primary key of one table in the other table can be done in 2
ways –
Customer (Customer ID, Customer Name, Address, PassNo.)
Holiday Pass (PassNo., Name of Resort, Location)
(or)
Customer (Customer ID, Customer Name, Address)
Holiday Pass (PassNo., Name of Resort, Location, Customer ID)
If we are to populate these tables with data we will find no repeating primary key
data and so the tables stand acceptable in both cases shown above. As one
Holiday Pass can be taken by only one Customer and vice versa, the table data
can be represented as shown below.
(or)
(ii) For Holiday Pass (PassNo., Name of Resort, Location, Customer ID):
Both the above options are correct . We need to select only one of these options
during Data Design and not both.
So finally, the general rule is that in a One to One Relationship of ERD, the
primary key of either table can be added to the other table.
Department Employee
Has / Belongs to
Fig 3. ERD showing the relationship between Department and Employee
By the ERD we should understand, as explained earlier that we will have at least
2 tables – one for Department data and the other for Employee data. Now let us
understand how the cardinality will be represented when it comes to table design.
Suppose in the Department table we also include the primary key of Employee to
show the relationship and populate such a Department table with data, we must
remember that one Department record will have many Employee primary data as
per the ERD in Fig 3.
Hence for Department (Department ID, Department Name, Employee ID) the
table will look like this:
For Employee (Employee ID, Employee Name, Address, Department ID), after
populating the table, it will look like:
The above given table proves to be acceptable as there are no repeating groups
and table seems to be normalized.
Hence the general rule is in a One to Many Relationship among Entities, the
primary key of the Entity that has the ‘One’ relationship should be added to
the data of the Entity that has the ‘Many’ relationship in ERD.
Member Book
By now, we should have understood that when a ‘Many’ aspect comes we can
see repeating groups if we form the wrong relationships between tables, hence
we should realize by now that in a Many to Many relationship in ERD, the primary
key of one cannot be added directly into the other table. So here we would have
to create a third table for the purpose of normalization.
So we will have a Member Table as we have a Member Entity; we will also have
a Book table as we have the Book Entity. In addition to this, a Third table
Transaction can also be created. If we are to diagrammatically represent this, it
would look like:
Member Book
Transaction
(Issue / Return / Renew) can have / is made on
can make / made by
Fig 5. Diagram to show the refined relationship from Fig 4
As you can see in Fig 5, we have broken up the relationships shown in Fig 4. –
Many to Many into two ‘One to Many’ relationships, by introducing the third to-be
table Transaction. So a Member can make many Transactions and one
Transaction can be made by only one Member. Similarly, one Book can have
many Transactions (as assumed above - one Book has many copies) and one
Transaction can be made only on one Book (assuming that many Books are
taken through many separate Transactions).
Now we can create the tables by looking at the rule for One to Many Relationship
which we explained earlier. So for the ‘Many’ Relationship Entity we must
consider the ‘One’ Relationship primary key.
Hence the tables from ERD of Fig 4 will now look like this:
So the general rule for Many to Many Relationships in ERD is to form the
tables we need to break the Many to Many into ‘One to Many’ or ‘One to
One’ relationships and then follow the corresponding rules, as explained
earlier, accordingly. A third table will be formed which will most probably
have two primary keys from the other two tables to form a composite key.
Coming back to Fig 1, let us try and covert this ERD into its corresponding tables.
We will break the ERD to understand what the individual tables will look like.
Course Instructor
Handled by / Handles
Fig 1.1 ERD showing the relationship between Course and Instructor
This is a ‘One to Many’ Relationship and hence in the ‘Many’ relationship Entity
table Course we must include the primary key of Instructor.
So the initial tables that are arrived at from this ERD (Fig 1.1):
Student Course
Attends / Attended by
Fig 1.2 ERD showing the relationship between Student and Course
This is a ‘Many to Many’ Relationship and hence we need to break this further
and include a third table while doing Data Design. We can break this relationship,
as explained earlier into ‘One – many’ or ‘One – One’ relationships (which ever is
relevant to the problem statement and assumptions taken) and include the third
Relationship Table. So in addition to Student and Course tables, we can a third
table named Registration and the relationship between Student and Registration
and between Course and Registration will both be One to Many. Hence the
Registration table will have a primary key from Student table and a primary key
from Course Table and these primary keys can act as Composite key in
Registration table. So the tables that can be derived from ERD given in Fig 1.2
are:
So the final tables arrived at from the ERD given in Fig 1 are:
Arriving at the tables from ERD is a simple process and you can verify this by
also arriving at the tables for the corresponding case by following the Rules of
Normalization.