您想对产品、用户、评论等发表评论吗?
或者找到评论所指的产品、用户、评论等?
对于前者,我会有表格将事物与他们的评论相关联:
create table join_products_comments (
product_id int (unique, i.e., one thread of comments per product),
comment_thread_id int
);
create table join_users_comments (
user_id int (unique, i.e., one thread of comments per user),
comment_thread_id int
);
其中 comment_thread 只是对每个评论引用的线程的引用:
create table comment_threads (
thread_id int (PK),
thread_name nvarchar2(256),
created datetime
);
create table comments (
comment_id int (PK),
comment_thread_id int (FK),
parent_comment_id int (FK),
user_id int (FK), -- person who posted the comment
comment text,
created datetime
);
因此,系统中的每个可评论实体都会有一个连接表和一个 comment_thread,等待急切的用户添加评论。或者您可以直接链接到根评论,而不需要这种间接方式。