Reputation: 89
I am working on a personal library database in MS SQL Server 2014 and I have two tables called Book, and Genre. The Genre table has a list of genres that a book can have. How can I let a book have multiple Genres with out repeating my attributes because each book might have a different number of Genres?
<Genre>
ID | Name
<Book>
ID | Title | AuthorID | GenreID | GenreID2 | GenreID3 | ... etc
Upvotes: 1
Views: 102
Reputation: 384
What you need is a Cross Reference table. The table might look like this:
<BookGenre>
GenreId | BookId
For each genre that applies to a book, you insert a record into this table with the appropriate GenreId and BookId.
Upvotes: 1