Many-to-Many relationship in SQL and how to avoid it?

  • The many-to-many relationship is a relationship where multiple rows from table A can correspond to multiple rows in table B.
  • A relationship that is multi-valued in both directions is called many-to-many relationship.
  • Student – teacher Example: An example of such a relationship is a school where teachers teach students. Each teacher teaches multiple students and each student can be taught by multiple teachers.
  • Using a Normalized design approach to your database schema, you will find that many-to-many Relationships between two objects A and B are commonly expressed as a third table C.
  • So you have a one-to-many relationship between A-to-C and a one-to-many relationship between B-to-C. In your junction Table C, each row contains a foreign key to the primary keys of Tables A & B.

Newer Post Older Post

Leave a Reply

naeemgik. Powered by Blogger.