Examples Problems
Examples Problems
Examples Problems
Solution:
Reducing Entity Relationship Diagram into Tables,
Convert ER diagram to tables, relational schemas, ER
model to relational model
Strong entity sets – Entity set that has a primary key to uniquely represent
each entity is Strong entity set.
Strong entity sets can be converted into relational schema by having the
entity set name as the relation schema name and the attributes of that
entity set as the attributes of relation schema.
Then we have,
Scientist (SID, SName, RArea, Country)
Invention (IID, IName, Year)
Relationship set – The association between two or more entity sets is termed
as relationship set.
A relationship may be either converted into a separate table or not. That
can be decided based on the type of the relationship. Only many-to-
many relationship needs to be created as a separate table.
Here, we are given a one-to-one relationship. That means, one entity
(record/row) of Scientist can be related to at most one entity
(record/row) of Invention entity.
Solution:
Strong entity sets
At first, let us identify and reduce all the strong entity sets (those
that have primary keys) into relational schemas.
Composite attributes
In entity sets Branch and Customer, the
attributes Br_add and Cust_add respectively are composite
attributes. To reduce the composite attributes we retain the
component attributes in the schema. That is, instead of Br_add, we
shall include the component attributes state, country and pin the
Branch table as follows;
Multi-valued attributes
Ph_no attribute of Customer entity set is a multi-valued attribute.
That is, it can have one or more values in it per record (row). To
reduce the multi_valued attribute, we need to create a separate
table with a new name with the multi_valued attribute as one
attribute along with the primary key of the base entity set as
follows;
Relationship sets
- For all others, the primary key of one side has to be included as the
foreign key of the other side (no need to create a separate table).
_ For each reality show, its name, genre, basic_info and participants
name. Any reality show has at least two or more participants.
_ For each television, its name, start year, head office. A television may
broadcasts multiple shows. Each show is broadcasted by exactly one
television.
_ For each user, his/her username, password, and age. A user may rate
multiple shows, and a show may be rated by multiple users. Each rating
has a score of 0 to 10.
Solution:
Reduction of ERD to Relational Schema - Solved
Exercise
Solution:
Notations used in the ERD for relationships
Step 1: First let us reduce the strong entity sets into schema. We have
the strong entity sets LOT, RAW_MATERIALS and
PRODUCTION_UNITS. They can be converted into schemas as follows;
Resultant schema:
After reduction, the schema looks like the following; [primary keys are
underlined, foreign keys are connected with the concerned primary keys
with headed arrows]
Trip Trip(tripNo)
M-to-M Relationship
SBetween(ShipNo, From_Address,
Pickup_time, To_Address, Dropoff_time)
1-to-M Relationship
Specialization
StopPoint StopPoint(Address)
(super class
entity) Warehouse(Address, port)
Warehouse
(sub-class entity) shopNpay(Address, openHrs)
shopNpay
(sub-class entity)
Trip(tripNo)
Journey(ID, LicNo, tripNo) – ID, LicNo, and tripNo all are foreign
keys referencing Driver, Truck, and Trip relations respectively.
StopPoint(Address)