I have one table “Books”, with a column “genres” where I want to reference to another table that contains list of genres.
The problem is that want to store more then one genres in column.
E.g,
ID | Author | Title | Genres
2 | David Baldacci |Stone Cold | 1,4 (action thriller )
table “Books Genres” with 2 columns Id and Genre.
1 Action
2 Drama
3 Comedy
4 Thriller
5 Horror
Can something like this be done? or it’s not practical and I should store genres as simple string?
It can be done, but shouldn’t.
It is bad database design – your database should be normalized.
I suggest an many-to-many table – with
genreIdandbookIdcolumns (being foreign keys each, and together forming a composite primary key). This will work as the link you need (a book can have many genres, each genre can write many books).Giving your book as an example with the
Book Genrestable, this would look like: