为简单起见,假设我的数据库有两个表,视频和用户。 视频是不同视频的列表,用户是不同用户的列表。
我需要能够记录用户何时观看某个视频,所以当他们再次观看视频时,我可以让他们知道他们已经看过了。
信息:可能会有成千上万的用户可能会有成千上万的视频。
我曾想过这样做的一种方式是为每个视频创建一个表格,或者为每个用户创建一个表格(两者都会导致数十万个表格)。
另一种方法是创建一个中性表,其中包含:userID(外键),videoID(外键)。 但是,我认为这会影响效率(和规范化),因为存在多值依赖关系,或两列中相同userID和videoID的倍数。
我对数据库还是比较新的,我觉得我缺少一些简单的东西。 任何帮助将不胜感激。
我正在使用MySQL。
For the sake of simplicity, let's say my database has two tables, videos and users. Videos being a list of different videos, and users being a list of different users.
I need to be able to have a record of when a user watches a certain video, so when they go to view the video again, I can let them know that they have already seen it.
Info: There will potentially be hundreds of thousands of users There will potentially be hundreds of thousands of videos.
One way I have thought of doing this is buy creating a table for each video, or a table for each user (Both would result in hundreds of thousands of tables).
Another way would be to create one neutral table, with the fields: userID(foreign key), videoID(foreign key). However, I believe this compromises efficiency (and normalization) because there would be multi-valued dependencies, or multiples of the same userID's and videoID's in the two columns.
I am still fairly new to databases, and I feel like I am missing something simple. Any help would be greatly appreciated.
I am using MySQL.
最满意答案
你的数据库应该有一个users表,一个videos表和一个userViews表。 userViews包含字段userId和videoId以及时间/日期字段。 当人们观看视频时将其填满。
规范化不会受到影响。
Your database should have a table for users, a table for videos and a table for userViews. userViews contains fields userId and videoId and a time/date field. Fill it up as people watch videos.
Normalization is not compromised.
更多推荐
发布评论