如何处理数据库中的数据副本?

时间:2022-09-20 10:55:25

What should I do if a user has a few hundred records in the database, and would like to make a draft where they can take all the current data and make some changes and save this as a draft potentially for good, keeping the two copies?

如果用户在数据库中有几百条记录,我应该怎么做,并且想要做一个草案,在那里他们可以获取所有的当前数据,并做一些修改,并将其保存为一个潜在的好的草案,保留这两个副本?

Should I duplicate all the data in the same table and mark it as a draft?

我是否应该将同一表中的所有数据复制并标记为草稿?

or only duplicate the changes? and then use the "non-draft" data if no changes exist?

或者只复制更改?如果没有变化,使用“非草稿”数据?

The user should be able to make their changes and then still go back to the live and make changes there, not affecting the draft?

用户应该能够做出他们的更改,然后仍然回到现场并在那里进行更改,而不影响草稿?

2 个解决方案

#1


2  

Just simply introduce a version field in the tables that would be affected.

只需在表中引入受影响的版本字段。

Content management systems (CMS) do this already. You can create a blog post for example, and it has version 1. Then a change is made and that gets version 2 and on and on.

内容管理系统(CMS)已经做到了这一点。例如,您可以创建一个博客文章,它有版本1。然后进行一个更改,然后获取版本2并继续进行。

You will obviously end up storing quite a bit more data. A nice benefit though is that you can easily write queries to load a version (or a snapshot) of data.

显然,您最终将存储更多的数据。不过,一个不错的好处是,您可以轻松地编写查询来加载数据的版本(或快照)。

As a convention you could always make the highest version number the "active" version.

作为一种约定,您可以将最高的版本号设置为“活动”版本。

#2


0  

You can either use BEGIN TRANS, COMMIT and ROLLBACK statements or you can create a stored procedure / piece of code that means that any amendments the user makes are put into temporary tables until they are ready to be put into production.

您可以使用BEGIN TRANS、COMMIT和ROLLBACK语句,也可以创建一个存储过程/代码片段,这意味着用户所做的任何修改都将放入临时表中,直到它们准备好投入生产。

If you are making a raft of changes it is best to use temporary tables as using COMMIT etc can result in locks on the live data for other uses.

如果您正在进行大量更改,那么最好使用临时表,因为使用COMMIT等会导致对其他用途的活动数据进行锁。

This article might help if the above means nothing to you: http://www.sqlteam.com/article/temporary-tables

如果上面的内容对您来说没有任何意义,本文可能会有所帮助:http://www.sqlteam.com/article/temporal -tables

EDIT - You could create new tables (ie NOT temporary, but full fledged sql tables) "on the fly" and name them something meaningful. For instance, the users intials, followed by original table name, followed by a timestamp.

编辑——您可以创建新的表(不是临时的,而是成熟的sql表)“on the fly”,并给他们命名一些有意义的东西。例如,用户在内部加上原始表名,然后是时间戳。

You can then programtically create, amend and delete these tables over long periods of time as well as compare against Live tables. You would need to keep track of how many tables are being created in case your database grows to vast sizes.

然后,可以编程地创建、修改和删除这些表,并对活动表进行比较。您将需要跟踪正在创建的表的数量,以防数据库扩展到巨大的大小。

The only major headache then is putting the changes back into the live data. For instance, if someone takes a cut of data into a new table and then 3 weeks later decides to send it into live after making changes. In this instance there is a likelihood of the live data having changed anyway and possibly superseding the changes the user will submit.

唯一令人头疼的是将这些变化重新输入到实时数据中。例如,如果有人从一个新表中抽取数据,然后3周后决定在进行更改后将其发送到live。在这个实例中,有可能实时数据已经发生了改变,并且可能取代用户将要提交的更改。

You can get around this with some creative coding though. There are many ways to tackle this, so if you get stuck at the next step you might want to start a new question. Hopefully this at least gives you some inspiration though.

你可以通过一些创造性的编码来解决这个问题。有很多方法可以解决这个问题,所以如果你在下一步遇到困难,你可能想要开始一个新的问题。希望这至少能给你一些启发。

#1


2  

Just simply introduce a version field in the tables that would be affected.

只需在表中引入受影响的版本字段。

Content management systems (CMS) do this already. You can create a blog post for example, and it has version 1. Then a change is made and that gets version 2 and on and on.

内容管理系统(CMS)已经做到了这一点。例如,您可以创建一个博客文章,它有版本1。然后进行一个更改,然后获取版本2并继续进行。

You will obviously end up storing quite a bit more data. A nice benefit though is that you can easily write queries to load a version (or a snapshot) of data.

显然,您最终将存储更多的数据。不过,一个不错的好处是,您可以轻松地编写查询来加载数据的版本(或快照)。

As a convention you could always make the highest version number the "active" version.

作为一种约定,您可以将最高的版本号设置为“活动”版本。

#2


0  

You can either use BEGIN TRANS, COMMIT and ROLLBACK statements or you can create a stored procedure / piece of code that means that any amendments the user makes are put into temporary tables until they are ready to be put into production.

您可以使用BEGIN TRANS、COMMIT和ROLLBACK语句,也可以创建一个存储过程/代码片段,这意味着用户所做的任何修改都将放入临时表中,直到它们准备好投入生产。

If you are making a raft of changes it is best to use temporary tables as using COMMIT etc can result in locks on the live data for other uses.

如果您正在进行大量更改,那么最好使用临时表,因为使用COMMIT等会导致对其他用途的活动数据进行锁。

This article might help if the above means nothing to you: http://www.sqlteam.com/article/temporary-tables

如果上面的内容对您来说没有任何意义,本文可能会有所帮助:http://www.sqlteam.com/article/temporal -tables

EDIT - You could create new tables (ie NOT temporary, but full fledged sql tables) "on the fly" and name them something meaningful. For instance, the users intials, followed by original table name, followed by a timestamp.

编辑——您可以创建新的表(不是临时的,而是成熟的sql表)“on the fly”,并给他们命名一些有意义的东西。例如,用户在内部加上原始表名,然后是时间戳。

You can then programtically create, amend and delete these tables over long periods of time as well as compare against Live tables. You would need to keep track of how many tables are being created in case your database grows to vast sizes.

然后,可以编程地创建、修改和删除这些表,并对活动表进行比较。您将需要跟踪正在创建的表的数量,以防数据库扩展到巨大的大小。

The only major headache then is putting the changes back into the live data. For instance, if someone takes a cut of data into a new table and then 3 weeks later decides to send it into live after making changes. In this instance there is a likelihood of the live data having changed anyway and possibly superseding the changes the user will submit.

唯一令人头疼的是将这些变化重新输入到实时数据中。例如,如果有人从一个新表中抽取数据,然后3周后决定在进行更改后将其发送到live。在这个实例中,有可能实时数据已经发生了改变,并且可能取代用户将要提交的更改。

You can get around this with some creative coding though. There are many ways to tackle this, so if you get stuck at the next step you might want to start a new question. Hopefully this at least gives you some inspiration though.

你可以通过一些创造性的编码来解决这个问题。有很多方法可以解决这个问题,所以如果你在下一步遇到困难,你可能想要开始一个新的问题。希望这至少能给你一些启发。