我可以使用 ROWLOCK、UPDLOCK 锁定连接 SQL 语句中的记录吗?
我有一个存储过程来获取我想要的数据:
SELECT a.SONum, a.Seq1, a.SptNum, a.Qty1, a.SalUniPriP, a.PayNum, a.InvNum,
a.BLNum, c.ETD, c.ShpNum, f.IssBan
FROM OrdD a JOIN OrdH b ON a.SONum = b.SONum
LEFT JOIN Invh c ON a.InvNum = c.InvNum
LEFT JOIN cus d ON b.CusCod = d.CusCod
LEFT JOIN BL e ON a.BLNum = e.BLNum
LEFT JOIN PayMasH f ON f.PayNum = a.PayNum
LEFT JOIN Shipment g ON g.ShpNum = c.ShpNum
WHERE b.CusCod IN (SELECT CusCod FROM UsrInc WHERE UseID=@UserID and UseLev=@UserLvl)
AND d.CusGrp = @CusGrp
将这些记录放入游标后,我使用 ROWLOCK、UPDLOCK 来锁定所有相关的发票号码。
SELECT InvNum FROM Invh WITH (ROWLOCK,UPDLOCK) WHERE InvNum =
当我在存储过程中使用 join 命令从几个表中选择表时,是否可以对表 INVH
发出锁定?
任何建议,请!
I have a stored procedure to get the data I want:
SELECT a.SONum, a.Seq1, a.SptNum, a.Qty1, a.SalUniPriP, a.PayNum, a.InvNum,
a.BLNum, c.ETD, c.ShpNum, f.IssBan
FROM OrdD a JOIN OrdH b ON a.SONum = b.SONum
LEFT JOIN Invh c ON a.InvNum = c.InvNum
LEFT JOIN cus d ON b.CusCod = d.CusCod
LEFT JOIN BL e ON a.BLNum = e.BLNum
LEFT JOIN PayMasH f ON f.PayNum = a.PayNum
LEFT JOIN Shipment g ON g.ShpNum = c.ShpNum
WHERE b.CusCod IN (SELECT CusCod FROM UsrInc WHERE UseID=@UserID and UseLev=@UserLvl)
AND d.CusGrp = @CusGrp
After I get those records into cursor, I used ROWLOCK, UPDLOCK
to lock all the related invoice numbers.
SELECT InvNum FROM Invh WITH (ROWLOCK,UPDLOCK) WHERE InvNum =
Can I issue locking on the table INVH
at the point I select the table from a few table using join command at my store procedure?
Any advice, please!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,可以,只要您正确设置 SQL 格式即可。您需要的一般模式如下:
其中
{}
是可选的(省略{}
)。因此,当您在要锁定的每个表上放置“WITH (UPDLOCK, ROWLOCK)
”子句时,它就会起作用。因此,您可以根据您的问题将锁放在您想要的位置。
Yes, you can, provided you format your SQL correctly. The general pattern you require is as follows:
Where
{}
is optional (omit the{}
). So lock as you put the "WITH (UPDLOCK, ROWLOCK)
" clause on each table you wish to lock, it will work.So you can put the lock where you want it, as per your question.