2009-07-28 84 views
0

我想實現評論,評級,標籤等模塊到我的實體。我的想法是:標籤,評論,評級等數據庫設計

comments_table - > COMMENT_ID,COM​​MENT_TEXT

使用實體 - > entitity1_id,entity1_text

ENTITY2 - > entitity2_id,entity2_text

entity1_comments - > entity1_id,COMMENT_ID

entity2_comments - > entity2_id,comment_id

....

這種方法是否正確?

回答

1

它比這更簡單。你會想是這樣的:

實體:ENTITYID EntityText

評論:CommentID AssocEntityID CommentText

凡AssocEntityID有一個外鍵關係到實體表ENTITYID列。

對於這個解決方案,以取得編號爲1的實體的所有意見,你可以這樣做:

SELECT CommentID, CommentText FROM Comments WHERE AssocEntityID = 1 
1

沒有,我建議只具有一個entity_comments表,它的意見和實體之間的交叉表。您必須將一個註釋表中的entity1和entity2標識作爲單獨的屬性。

所以它看起來像:

​​

一個簡單的選擇可能是:

select text 
    from entity1 
    , entity_comments 
    , comments_table 
    where entity1.id = entity_comments.entity1_id 
    and entity_comments.comment_id = comments_table.id 
+0

你說插入兩個屬性使用實體ANS ENTITY2屬性到entitycomments表。如果我有10個實體呢? 10個獨立的屬性和大量的空值? – 2009-07-28 17:00:29