SQL Server 行锁 [英] SQL Server row lock

查看:32
本文介绍了SQL Server 行锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 SQL Server 2005 中行锁.我执行一个 sql 来行锁,那就是

How to row lock in SQL Server 2005. I execute a sql for row locking and that is

SELECT *
FROM authors
WITH (HOLDLOCK, ROWLOCK)
WHERE au_id = '274-80-9391'

它工作正常,但在这种情况下,行被锁定用于更新而不是用于选择.我只想知道如何锁定一行,结果另一个用户在 SQL Server 中发出 SQL 时看不到该行.请指导我.谢谢

it work fine but in this case row is lock for update not for selection. I just want to know how to lock a row as a result another user can not see that row when issue a SQL in SQL Server. please guide me. thanks

推荐答案

您不能隐藏一行,使其不会被其他 SQL 查询看到.如果您打开一个事务、锁定一行并保持打开该事务,您可能会导致其他 SQL 查询阻塞,等待您的事务结束和锁清除.但是,如果查询以不同的事务隔离级别(例如:Read Uncommitted)运行,那么它们将绕过锁并仍然看到该行的值.

You can't hide a row so that it won't be seen by other SQL queries. If you open a transaction, lock a row, and hold open the transaction, you can cause other SQL queries to block waiting for your transaction to end and the lock to clear. However if the queries are run with a different transaction isolation level (e.g.: Read Uncommitted) then they will bypass the lock and still see that row's values.

这篇关于SQL Server 行锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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