문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

It can be locked. In the Edit Panel, try to insert a row and violate the Primary Key constraint. You will get an error dialog popup message. The table will now be locked while you are reading that message. If you walk away without confirming the message, that table will be locked indefinitely. I just confirmed this with both SSMS 2008R2 and SSMS 2012.

The data won't be locked by default in the SSMS GUI editor.

If you make changes and try to save, you'll get errors/warning ato overwrite/discard etc. I can't test right now to see the exact messages, sorry.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top