可以在sql中的commit语句之后保存数据 [英] is it possible to save data after commit statement in sql

查看:375
本文介绍了可以在sql中的commit语句之后保存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果10个用户一次处理一个表(例如,A1,A2,A3 ....,A10)。每一个都在同一表并行(即插入,更新和删除)上执行DML操作。如果用户A1在其他人执行操作时提交事务。可以保存所有的事务操作(是/否)
如果是,那么为什么?
如果没有,为什么?

If 10 users are working on one table at once (e.g.-A1,A2,A3....,A10). Every one is performing DML operation on same table parallel (i.e. insert,update and delete). If user A1 commit the transaction when others are performing operations. is possible to save all's transaction operations.(Yes/No) If Yes then why? If No the Why?

推荐答案

根据 ACID 隔离交易。

如果用户A1创建了一个事务,那么只有他可以提交它。这将使其他用户的所有或其他更改都不可见。根据事务的隔离级别,其他用户只有在提交自己的活动事务之后才会看到其他用户提交的更改(请参阅 phantom / dirty / non-repeatable reading )。

If a user A1 creates a transaction, then only he can commit it. This will make either all or none of his changes visible to other users. Depending on the isolation level of the transactions, other users will see committed changes by other users only after their own active transaction is committed (see phantom/dirty/non-repeatable reads).

想象一下:

我正在改变数据库中的东西。例如,我删除用户A1已更改的对象。如果他的提交也提交我的事务,会发生什么?他应该得到一个错误,因为对象已经/将会消失吗?或者我应该得到一个错误,因为对象被另一个用户修改了?

I'm in the middle of changing something in the database. For example, I'm deleting an object which user A1 has changed. If his commit commits my transaction, too, what should happen? Should he get an error because the object has/will vanish? Or should I get an error because the object was modified by another user?

没有简单的方法来解决这些冲突。

There is no simple way to resolve these conflicts.

云数据库通过保存所有对象的历史记录来解决它。因此,当用户A1更改对象并删除它时,DB将记录这两个更改,但保持对象。我可以及时移动以查看A1的更改,我也可以看到我的删除。

Cloud databases solve it by keeping a history of all objects. So when user A1 changes an object and I delete it, the DB will record the two changes but keep the object around. I can move in time to see A1's change and I can also see my "deletion".

另一点:您可以编写一个服务器,同步所有用户的更改。所以总是只有一个事务打开。如果两个用户更改相同的对象,您如何解决冲突?

Another point: You could write a server which synchronizes the changes made by all users. So there would always be only a single transaction open. If two users change the same objects, how do you resolve the conflicts?

或者您可以编写一个服务器跟踪所有事务并提交它们在一个,如何确保半有效对象写入数据库(如没有项目的订单,没有总计的发票,没有地址的客户)?

Or you could write a server which keeps track of all transactions and commits them all at one, how do you make sure that half-valid objects are written to the database (like orders without items, invoices without totals, customers without addresses)?

这篇关于可以在sql中的commit语句之后保存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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