解决Sybase更新表期间的并发问题

发布于 2024-12-11 11:20:46 字数 623 浏览 0 评论 0原文

我在 Sybase 中有一个包含以下代码的过程。

begin transaction get_virtual_acc

    UPDATE store_virtual_acc SET isProc = 1, Uid = @uid, DateReserv = getdate()  
    from store_virtual_acc (index idx_id) WHERE id = (SELECT min(id) FROM store_virtual_acc (index idx_uid) where  Uid = null and isProc = null)  

commit transaction get_virtual_acc 

问题是,当多个用户同时调用该过程时,他们可以接收相同的 min(id) 并使用不同的值 @uid 更新表中的同一行。结果是数据失真。需要实现一个结果,即如果该行已经选择更新单个用户,则其他用户无法选择它。表具有锁定类型的数据行。

尝试使用事务级锁定如下 设置事务隔离级别3 在事务开始之前但调用过程的应用程序出现异常 java.sql.SQLException:您的服务器命令(系列 id # 0,进程 id # 530)遇到死锁情况。请重新运行您的命令。

我将不胜感激任何帮助。

I have a procedure in Sybase with the following code.

begin transaction get_virtual_acc

    UPDATE store_virtual_acc SET isProc = 1, Uid = @uid, DateReserv = getdate()  
    from store_virtual_acc (index idx_id) WHERE id = (SELECT min(id) FROM store_virtual_acc (index idx_uid) where  Uid = null and isProc = null)  

commit transaction get_virtual_acc 

The problem is that when the procedure is called multiple users concurently they can receive the same min(id) and update same row in the table with different value @uid. The result is a distortion of the data. It is necessary to achieve a result, that if the line has already selected for update a single user, the other can't select it. Table have lock type datarows.

Tried to use a transaction-level locking as follows
set transaction isolation level 3
before the transaction begin but aplication wich call the procedure get exception
java.sql.SQLException: Your server command (family id # 0, process id # 530) encountered a deadlock situation. Please re-run your command.

I would be grateful for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光下的泡沫是彩色的 2024-12-18 11:20:46

尝试这样的事情:

begin transaction get_virtual_acc

UPDATE store_virtual_acc SET isProc = 1, Uid = @uid, DateReserv = getdate()  
from store_virtual_acc (index idx_id) WHERE id = (SELECT min(id) FROM store_virtual_acc (index idx_uid) holdlock where  Uid = null and isProc = null )  

commit transaction get_virtual_acc 

关键字是holdlock

Try something like this:

begin transaction get_virtual_acc

UPDATE store_virtual_acc SET isProc = 1, Uid = @uid, DateReserv = getdate()  
from store_virtual_acc (index idx_id) WHERE id = (SELECT min(id) FROM store_virtual_acc (index idx_uid) holdlock where  Uid = null and isProc = null )  

commit transaction get_virtual_acc 

The keyword is holdlock

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文