Sql表存储编辑历史

编程入门 行业动态 更新时间:2024-10-18 18:16:05
本文介绍了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表存储编辑历史

本文发布于:2023-10-24 14:20:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524163.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编辑   历史   Sql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!