Database One to Many Relationship with example
One to Many relationship is the most common relationship and your database entity relationship diagram (ERD) will be full of this kind of relationship.
Examples
1. Master-detail. You have a master record with many detail records. For example an order, there will be a master record with the order date, person placing the order, etc. And then detail records of everything ordered. The master record will have many details, and the detail will have only 1 master.
Examples
1. Master-detail. You have a master record with many detail records. For example an order, there will be a master record with the order date, person placing the order, etc. And then detail records of everything ordered. The master record will have many details, and the detail will have only 1 master.
2. Supervisor-subordinates. A supervisor will have one or many subordinates. A subordinate will have only 1 manager.
3. Division- department. A division will have one or many departments. A department will belong to only 1 division.
Let’s look at the Master - Detail
The two entities could translate into the following two tables:
In the Master table, the OrderNumber is the primary key. In the detail table, OrderNumber is the foreign key. The primary key in the Detail table will be a combination of OderNumber and LineNumber.
The information in the tables could look as follows:
Master:Detail:
Comments
Post a Comment