Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are data rows locked when editing them in SQL Server Management Studio 2008?

When I right-click on a table in SQL Server Management Studio and choose 'Edit top 200 rows', at what point, if ever, would the data that I'm looking at be locked?

A colleague of mine stated that when viewing data in this way, the data rows can be locked (I think when he said if you put a cursor on a row and start editing data).

Is this the only time the data can be locked in this context?

like image 804
Jason Evans Avatar asked Dec 22 '11 10:12

Jason Evans


1 Answers

It's not true. Run this script in one window (and leave it running):

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

Every 5 seconds, it flips the value of the Val1 column, and prints Updated in the messages tab (assuming you're set to "results in grid").

Then, in another instance of SSMS, open the Tx table and start editing the single row in there. Observe that the script continues to perform updates.

like image 200
Damien_The_Unbeliever Avatar answered Nov 03 '22 00:11

Damien_The_Unbeliever