Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 标签、注释、评级等数据库设计_Database_Tags_Rating_Comments - Fatal编程技术网

Database 标签、注释、评级等数据库设计

Database 标签、注释、评级等数据库设计,database,tags,rating,comments,Database,Tags,Rating,Comments,我想为我的实体实现诸如评论、评级、标记等模块。我的想法是: 注释表->注释id,注释文本 entity1->entity1\u id,entity1\u文本 entity2->entity2\u id,entity2\u文本 entity1\u注释->entity1\u id,注释\u id entity2\u注释->entity2\u id,注释\u id 这种方法正确吗?它比那简单。你会想要这样的东西: 实体:EntityID EntityText 注释:CommentID AssocEn

我想为我的实体实现诸如评论、评级、标记等模块。我的想法是:

注释表->注释id,注释文本

entity1->entity1\u id,entity1\u文本

entity2->entity2\u id,entity2\u文本

entity1\u注释->entity1\u id,注释\u id

entity2\u注释->entity2\u id,注释\u id


这种方法正确吗?

它比那简单。你会想要这样的东西:

实体:EntityID EntityText

注释:CommentID AssocEntityID CommentText

其中,AssocEntityID与实体表EntityID列具有外键关系

对于此解决方案,要获取ID为1的实体的所有注释,请执行以下操作:

SELECT CommentID, CommentText FROM Comments WHERE AssocEntityID = 1

不,我建议只使用一个实体注释表,它是注释和实体之间的一个相交表。在one comments表中,必须将entity1和entity2 ID作为单独的属性

所以它看起来像:

entitiy1 -> entity_comments <- comments_table
entitiy2 -> entity_comments <- comments_table

您可以说将两个属性作为entity1和entity2属性插入entitycomments表。如果我有10个实体呢?10个独立的属性和大量的空值?那么此时您可能需要完全重新设计您的表结构。在每个新的实体表中不断向intersect表添加属性会变得很混乱。如果实体中每行只有一条注释,则可以将comments.id放在entity1表中,而不放在intersect表中。intersect表允许每个entity1行有多个注释。
select text
  from entity1
     , entity_comments
     , comments_table
  where entity1.id = entity_comments.entity1_id
    and entity_comments.comment_id = comments_table.id