Sql表存储编辑历史 [英] Sql table store edit history

查看:106
本文介绍了Sql表存储编辑历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用sql server数据库存储数据的项目。我有一张表:

I am working on a project using sql server database for storing data. I have a table:

记录

  Id                   - (PK)
  RecordTitle          - (varchar(400))
  IsDeleted            - (bit)
  LastUpdatedAtUtc     - (long - unix timestamp)
  LastUpdatedById      - (FK to UserTable)

用户可以添加/编辑/删除多个记录。所以UserTable和RecordTable之间的关系是1到许多

我想在同一个表中存储编辑/删除记录的历史记录。因此,如果记录被删除,我们只需设置 IsDelete 列值 True

I want to store Edit/Delete history of record in the same table. So if record is deleted we just set IsDelete column value True.

同样,我想将编辑历史记录存储在同一张桌子。因此,每当用户编辑任何记录时,原始记录将不会被更改,而是插入一个新的记录与更改。

Similarly I want to store Edit history in the same table. So that whenever user edit any record the original record will not get changed instead a new record is inserted with the changes.

我想知道应该是什么有效的方法处理这个(事情。我们需要在记录表中添加新列以存储编辑历史记录。如果是,那么这些列是什么?

I want to know what should be the efficient way to handle this. Do we need to add new columns in the record table to store edit history. If yes, then what are those columns?

推荐答案

有很多方法。

1)取一列ParentId,每当任何用户编辑记录时,使用带有旧记录ID的ParentId插入新记录。所以你将拥有所有的历史记录。

1) Take a column ParentId and whenever any user edit the record, insert new record with ParentId with old record Id. So you will have all history.

2)拿另一个名为history表的表,并保存该表中的旧记录,并在原始表中进行更新。不要忘记将原始表的ID作为一个单独的列。

2) Take another table named history table and save old record in that table and do update in original table. Don't forget to mention original table's id as one separate column.

3)您可以将一列作为history_column,您可以在其中保存从OLD更改的字符串到新的。

3) You can take one column as history_column where you can save a string of what is changed from OLD to NEW.

这篇关于Sql表存储编辑历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆