如何在某些SQL行上运行进程时锁定它们? [英] How do I lock certain SQL rows while running a process on them?

查看:77
本文介绍了如何在某些SQL行上运行进程时锁定它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作有一个财务应用程序,用VB.NETSQL编写,可以同时处理多个用户.

My work has a financial application, written in VB.NET with SQL, that several users can be working on at the same time.

在某个时候,一个用户可能决定发布他们(可能还有其他人)当前正在处理的那批条目.

At some point, one user might decide to Post the batch of entries that they (and possibly other people) are currently working on.

很显然,我不再希望任何其他用户之后添加,编辑删除该批次中的条目 发布过程已启动.

Obviously, I no longer want any other users to add, edit, or delete entries in that batch after the Post process has been initiated.

我已经看到我可以通过在Post进程开始时打开SQL事务来锁定所有数据,但是该过程可能相当漫长,因此我不希望为完成该功能可能需要几分钟.

I have already seen that I can lock all data by opening the SQL transaction the moment the Post process starts, but the process can be fairly lengthy and I would prefer not to have the Transaction open for the several minutes it might take to complete the function.

是否有一种方法可以仅锁定我知道需要通过VB.NET代码进行操作的记录?

Is there a way to lock just the records that I know need to be operated on from VB.NET code?

推荐答案

如果您使用的是Oracle,则将在锁定的行上选择更新.

If you are using Oracle you would Select for update on the rows you are locking.

这是一个例子

SELECT address1 , city, country
FROM location
FOR UPDATE;

这篇关于如何在某些SQL行上运行进程时锁定它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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