DBMS Lab Assignment 1- ER Diagram
DBMS Lab Assignment 1- ER Diagram
An entity type within ER diagram is turned into a table. You may preferably keep the same
name for the entity or give it a sensible name but avoid DBMS reserved words as well as avoid
the use of special characters. Each attribute turns into a column (attribute) in the table. The
key attribute of the entity is the primary key of the table which is usually underlined. It can be
composite if required but can never be null.
It is highly recommended that every table should start with its primary key attribute
conventionally named as TablenameID.
The initial relational schema is expressed in the following format writing the table names with
the attributes list inside a parentheses as shown below for
Persons( personid , name, lastname, email )
Persons and Phones are Tables. name, lastname, are Table Columns (Attributes).
1
Department of Computer Science & Information Technology
2. Multi-Valued Attributes
If you have a multi-valued attribute, take the attribute and turn it into a new entity or table of
its own. Then make a 1:N relationship between the new entity and the existing one. In simple
words. 1. Create a table for the attribute. 2. Add the primary (id) column of the parent entity
as a foreign key within the new table as shown below:
3. 1:1 Relationships
To keep it simple and even for better performances at data retrieval, I would personally
recommend using attributes to represent such relationship. For instance, let us consider the
case where the Person has or optionally has one wife. You can place the primary key of the
wife within the table of the Persons which we call in this case Foreign key as shown below.
Or vice versa to put the personid as a foreign key within the Wife table as shown below:
2
Department of Computer Science & Information Technology
4. 1:N Relationships
This is the tricky part ! For simplicity, use attributes in the same way as 1:1 relationship but
we have only one choice as opposed to two choices. For instance, the Person can have a House
from zero to many , but a House can have only one Person. To represent such relationship the
personid as the Parent node must be placed within the Child table as a foreign key but not the
other way around as shown next:
It should convert to :
5. N:N Relationships
We normally use tables to express such type of relationship. This is the same for N − ary
relationship of ER diagrams. For instance, The Person can live or work in many countries.
Also, a country can have many people. To express this relationship within a relational schema
we use a separate table as shown below:
3
Department of Computer Science & Information Technology
It is recommended to use table to represent them to keep the design tidy and clean
regardless of the cardinality of the relationship.
Practice Example
4
Department of Computer Science & Information Technology
Implementation Question:- Draw an ER diagram for the following problem statements and
then convert them into database relational schema
5
Department of Computer Science & Information Technology