在SQL Server Management Studio 2008中编辑数据行时是否锁定了数据行?

Jas*_*ans 7 sql-server-2008 rowlocking

当我右键单击SQL Server Management Studio中的表并选择"编辑前200行"时,如果有的话,我正在查看的数据是否会被锁定?

我的一位同事表示,以这种方式查看数据时,数据行可以被锁定(我想当他说你把光标放在行上并开始编辑数据时).

这是唯一可以在此上下文中锁定数据的时间吗?

Dam*_*ver 5

这不是真的.在一个窗口中运行此脚本(并使其保持运行):

create table Tx (
    ID int not null,
    Val1 varchar(20) not null
)
go
insert into Tx (ID,Val1)
select 1,'abc'
go
set nocount on
while 1=1
begin
    update Tx set Val1 = CASE WHEN Val1='abc' then 'def' else 'abc' end
    RAISERROR('Updated',10,1) WITH NOWAIT
    WAITFOR DELAY '00:00:05'
end
Run Code Online (Sandbox Code Playgroud)

每隔5秒,它会翻转Val1列的值,并Updated在消息选项卡中打印(假设您已设置为"结果为网格").

然后,在另一个SSMS实例中,打开Tx表并开始编辑那里的单行.观察脚本继续执行更新.