I’m making a basic movie online store for a project and I want users to be able to select movies by genre, e.g.:
- All
- Terror
- Action
- Documentaries
- Sci-Fi
- …
What is the best way to store movies in the database to match this structure.
First Way
Sort movies by genre and create separate tables, that is, a table for the action genre, one for documentaries, one for sci-fi and so with the others. With this approach, there would be no clear way to join the tables to produce the list of all movies
Second Way
Place all movies in a single table, place the genres in another table, and establish a foreign key relationship between the 2 based on genre
Or is there another better way to do this?
Thanks in advance
Not your first way: that’s not a relational database as you duplicate like information.
2nd way is more appropriate if you’re looking to be relational.
Movies in one table
MovieType in a second table.
Movies table contains a FK to MovieType which lists the names of the genre.