0

I have a two variants of DB structure.

First: enter image description here

Here is one comments table, and two special table 'news_comments' and 'photos_comments' which connect comment with material.

Second variants: enter image description here

Here only 3 tables, without connector tables, but table comments have a special field 'type', which will be used with query.

For example: SELECT * FROM comments WHERE type = 'news';

Question: I don't know which variant is better. I think second, but is it correct?

4

2 回答 2

1

对我来说,第一个解决方案似乎支持多对多关系,并且将是我的第一选择。

2nd 只支持单张照片评论和单条新闻评论。

于 2013-05-22T16:28:02.193 回答
1

Unless a single comment can apply to more than one photo and/or news item, the 2nd option better represents and "enforces" the logical concept in data. But, I'd recommend replacing photos_id and news_id with item_id, which holds either a photos_id or a news_id, and changing type from a varchar to an enum('news','photo').

Again, this is under the assumption that any given comment applies to one news item or one photo, never both, and never more than one (which is usually how commenting systems work, eh?).

于 2013-05-22T16:28:41.317 回答