In a database management system, a Many-to-Many relationship is a relationship between several instances of one entity and multiple instances of another entity, i.e. both entities can have multiple relationships with each other.
In this article, we will dive deeper into the Many-to-Many Relationship in DBMS according to the GATE Syllabus for (Computer Science Engineering) CSE. Keep reading ahead to learn more.
What is a Many-to-Many Relationship in DBMS?
This type of relationship exists when each of the records of the first table can be associated with one or more records of the second table, as well as a single record of the second table may be related to one or more records of the first table. A Many-to-Many relationship is formed by two one-to-many relationships that are connected by an ‘associate table’ or ‘linking table.’ By having fields that are the primary keys of the other two tables, the bridging table connects two tables. The following example will help us comprehend this.
Example
When the entity types ‘Customer’ and ‘Product’ are combined, each customer can purchase several products, and a product can be purchased by multiple customers.
To grasp the concept of a linking table in this context, consider the ‘Order’ entity as a linking table that connects the ‘Customer’ and ‘Product’ entities. This Many-to-Many relationship can be broken down into two one-to-many partnerships. To begin with, each ‘Customer’ can have several ‘Orders,’ whereas each ‘Order’ is only associated with one ‘Customer.’ Second, each ‘Order’ is associated with only one Product, despite the fact that several orders for the same Product may exist.
The concept of linking in the previous example can be understood by considering all of the attributes of the entities ‘Order,’ ‘Customer,’ and ‘Product.’ The primary keys of both the ‘Product’ and ‘Customer’ entities are included in the connecting table, i.e. the ‘Order’ table, as can be seen in the above example. When referring to the respective table from the ‘Order’ table, these keys operate as foreign keys.
Keep learning and stay tuned to get the latest updates on the GATE Exam along with Eligibility Criteria, GATE Syllabus for CSE (Computer Science Engineering), GATE CSE Notes, GATE CSE Question Paper, and more.
Also Explore,
Comments