

InterviewSolution
Saved Bookmarks
1. |
Discuss Different types of relationships along with examples? |
Answer» One-to-One RelationshipSuch a relationship exists when each record of one table is related to only one record of the other table.For example,\xa0If there are two entities ‘Person’ (Id, Name, Age, Address)and ‘Passport’(Passport_id, Passport_no). So, each person can have only one passport and each passport belongs to only one person.One-to-Many or Many-to-One RelationshipSuch a relationship exists when each record of one table can be related to one or more than one record of the other table. This relationship is the most common relationship found. A one-to-many relationship can also be said as a many-to-one relationship depending upon the way we view it.For example,\xa0If there are two entity type ‘Customer’ and ‘Account’ then each ‘Customer’ can have more than one ‘Account’ but each ‘Account’ is held by only one ‘Customer’. In this example, we can say that each Customer is associated with many Account. So, it is a one-to-many relationship. But, if we see it the other way i.e many Account is associated with one Customer then we can say that it is a many-to-one relationship.Many-to-Many RelationshipSuch a relationship exists when each record of the first table can be related to one or more than one record of the second table and a single record of the second table can be related to one or more than one record of the first table. A many-to-many relationship can be seen as a two one-to-many relationship which is linked by a \'linking table\' or \'associate table\'. The linking table links two tables by having fields which are the primary key of the other two tables. We can understand this with the following example.Example:\xa0If there are two entity type ‘Customer’ and ‘Product’ then each customer can buy more than one product and a product can be bought by many different customers. | |