Thursday, 2 March 2017

Explain one-to-many relationship with example in DBMS

What is one-to-many relationship in DBMS, one-to-many relationship example, cardinality ratio one-to-many


One-to-many relationship


If an entity [a record] of one entity set is associated with zero or more entities of the other entity set, then the cardinality ratio is said to be one-to-many from one side entity set to the many side entity set.

When we would say the relationship is one-to-many?
Assume two entity sets A and B. The relationship is one-to-many from A to B if and only if “an entity in A is associated with zero or more entities (records) in B and an entity in B is associated with only one entity (record) in A”.
If we put in simpler terms, entity set B is the many side for A and entity set A is the one side for B.

Example:
Let us assume a database for Airline Reservation System. Further assume that there are two entity sets Flights and Flight_Attendants to model the flight details and the flight attendants details respectively. If one flight can have many attendants, then this relationship can be modeled as one-to-many from Flight to Flight_Attendants.
When we say that the relationship type is either one-to-many or many-to-one, it is always important to say which side is one and which side is many to avoid ambiguity.
Sample one-to-many relationship between entity sets

Observe carefully from the above figure the following;
  • Each flight is having one or more attendants. [look from flight to flight_attendant]
  • Each flight attendant is allotted with exactly one flight. [look from flight_attendant to flight]
The ER diagram for this case is shown below;
One-to-many relationship Has between entity sets Flight and Flight_Attendant

This can be read as, one flight has many flight attendants and one flight attendant is attending only one flight.
 
*************













No comments:

Post a Comment

SQL exercises for beginners one

SQL Exercises for Beginners / Simple SQL Exercises with Answers / Solved SQL exercises / SQL solved exercises with simple conditions / So...