0

所以我创建了一个用户通知系统,我有一个 user_notifications 表结构如下:

id
receiver_id
sender_id
action
action_type
entity_id
timestamp

现在,其他表中的值通过“entity_id”列连接到通知。所以假设我也有这张名为videos_watched的表:

video_id
user_id
time_watched_for

它们从user_notifications .entity_id 连接到videos_watched .video_id

我要决定的是,将数据也存储在第二个表中是否是一件坏事。我应该将user_notifications表视为交互表,而不是实际可靠地存储用户数据的地方吗?

4

2 回答 2

2

The way I would approach this task is by breaking the data you are recording into manageable and logical chunks (although this is influenced by the amount of usage and the actual information you are wanting to pull out).

For instance, if the situation is that you are recording the following types of data:

  • user information (email, id, name etc)
  • videos (id, title, filename etc)
  • videos watched (video_id, user_id, time_watched_for)

Then it may make sense to store the data in separate tables so that the information is separated in a meaningful way.

So in that sense it would also make sense to have you initial table for notifications (although this looks more like a notification logs table):

  • notification table (id, receiver_id, sender_id, action, action_type, entity_id, timestamp)

Essentially, storing the data in a separate table isn't a bad idea, as long as there is a meaningful or logical reason to store it there such as logical data separation.

于 2012-10-30T00:06:57.653 回答
0

Generally, it's a bad idea to have redundant data in your database (non-normalized) because:

  • It takes up more space.
  • It's more cumbersome to maintain and takes longer to write (you are writing the same data to multiple places).
  • You can get an inconsistent database (like if you mess up the point above and don't write to all the places you need to).

The only reason to ever have redundant data that I can think of is because you absolutely need a performance boost for some kind of join that you will be doing and reading from all the time. If you have redundant data, you can eliminate the join/lookup and read straight from a single table.

于 2012-10-30T00:08:25.207 回答