保存修订历史记录的"最佳"方式取决于您的具体目标/约束条件 - 您还没有提到这些.
但这里有一些关于你的两个建议方法的想法:
为帖子创建一个表,为帖子历史创建一个表,例如:
create table posts (
id int primary key,
userid int
);
create table posthistory (
postid int,
revisionid int,
content varchar(1000),
foreign key (postid) references posts(id),
primary key (postid, revisionid)
);
Run Code Online (Sandbox Code Playgroud)(显然会有更多的列,外键等)这很容易实现并且易于理解(并且很容易让RDBMS保持参照完整性),但正如您所提到的那样可能导致posthistory有太多行要快速搜索足够.
注意,它postid是posthistory(以及PK posts)中的外键.
when I add a new version, replace the post with the same id in the post table, and also add this to the revision table.(这可能是SE网站使用的,基于SE数据资源管理器中的数据转储.或者可能不是,我无法分辨.)
对于这种方法,postid也是posthistory表中的外键,以及表中的主键posts.
| 归档时间: |
|
| 查看次数: |
1948 次 |
| 最近记录: |