简体   繁体   中英

Database design one Table or two Tables

I have a question about database design.
For example, I have two type of objects, one is movie, the other is TvShow.
Of course, there are some same field, like name cast story line etc.
There are also lots of different columns, like season episode etc.
Actually every episode is movie-like.

Maybe there are large quantities of data.
How to design ?
A) One table named video and two tables named movie and TvShow. The video table has the common columns.

B) Two tables named movie and TvShow.

Which is better and why? Thank you~

Unless you have specific reasons to do otherwise, I would recommend alternative "A", with three tables. Especially if you need to refer to videos in general from other tables.

Use a common primary key, where the primary keys in the two tables TVshow and Movie are also foreign keys to the primary key in Video. Now you can refer to TV shows, to movies, or to videos in general, by using foreign keys to one of the three tables.

Performance will be slower than with two tables (or a solution with a single table), since now the data is spread out in several places, and the queries will be a bit more complicated. If you are sure you need better performance you may have to use a different design. But it is a very common error to just assume that performance will be an issue. With proper indexing standard relational databases can be very fast, even when searching in very large data sets.

Having One Video table and two tables movie and TvShow complicates things a bit. Say you want to retrieve all TV Shows, you will need a link to the videos table. Of course on the downside you will have some "duplicate" field values, but since performance is critical and directly related to your selects, better go for option B.

Even your inserts will be quicker in B since in A, 2 inserts are required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM