+ 6
many-to-many relationship
Can anyone fully explain many-to-many relationship in mysql?
3 Respostas
+ 4
An example of a many to many relationship would be between authors and books. A book can have many authors. An author can write many books.
The typical and probably best way to represent a many to many relationship is to create a bridge table. For this books to authors relationship, you could call this bridge table "book_author". Each record in the book_author table would reference a book and an author. More specifically, the table could be created with a statement like:
create table book_author (
book_id references book(id),
author_id references author(id)
);
You might also want a composite unique constraint to indicate that the book_id and author_id pair should be unique. Duplicated bridge table records can be a pointless mess that bloats your database and complicates some application code.
More details are at:
https://en.wikipedia.org/wiki/Many-to-many_(data_model)
+ 3
Josh Greig
Perfect
Thank you
+ 1
Josh Greig answer is perfect. Is it possible to mark it as correct answer?