Sybase: trying to lock a record on select so another caller does not get the same one

喜你入骨 提交于 2019-12-04 19:15:50
KM.

since you are selecting just one row (TOP 1) why not just use a standard locking hint and forget the cursor:

BEGIN TRANSACTION

SELECT @PK=ID FROM YourTable WITH (UPDLOCK, HOLDLOCK, READPAST) WHERE ...

UPDATE ....
WHERE pk=@PK

COMMIT

if you really do need to loop, google "CURSOR FREE LOOP"

What are the different ways to replace a cursor?

you can loop by SELECTing the next MIN(PK)>@CurrentPk while using the locking hints on the SELECT.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!