INF: Locking Behavior of Updates and Deletes in SQL ServerID: Q125770
|
UPDATE and DELETE statements that require a table scan result in an exclusive lock held on the modified table.
Page 103 the SQL Server "Troubleshooting Guide" states:
...an exclusive table lock is usually acquired for a mass update
as a result.
set showplan on
go
begin tran
update authors
set city = 'Ft. Worth'
where au_id = '172-32-1176'
go
STEP 1
The type of query is BEGINXACT
STEP 1
The type of query is UPDATE
The update mode is direct
FROM TABLE
authors
Nested iteration
Using Clustered Index
TO TABLE
authors
spid locktype table_id page dbname
------ -------------------- ----------- ----------- ---------------
5 Ex_intent 16003088 0 pubs
5 Ex_page 16003088 352 pubs
5 Update_page 16003088 352 pubs
STEP 1
The type of query is BEGINXACT
STEP 1
The type of query is UPDATE
The update mode is deferred
FROM TABLE
authors
Nested iteration
Table Scan
TO TABLE
authors
spid locktype table_id page dbname
------ -------------------- ----------- ----------- ---------------
5 Ex_table 16003088 0 pubs
Statement Table Lock Page Lock
---------------------------------------------------------------------
Insert IX X
Using Select IS S
Index Select w/Holdlock IS S
Update IX U,X
Delete IX X
Without Select IS S
Using Select w/Holdlock S --
Index Update X --
Delete X --
Create clust. Index X --
Create non-cl. Index S --
Lock Compatibility - Table Locks
IS IX S X
----------------------------------------------------------------------
IS YES YES YES NO
IX YES YES NO NO
S YES NO YES NO
X NO NO NO NO
Lock Compatibility - Page Locks
S U X
----------------------------------------------------------------------
S YES YES NO
U YES NO NO
X NO NO NO
IS = Intent Shared; Intent locks flag at table level type of page
locks held
IX = Intent Exclusive
S = Shared
X = Exclusive
U = Update; Used for read/modify/write operations
Q75722 : INF: Reducing Lock Contention in SQL Server
Q122485 : INF: Identifying SPID Responsible for Lock Chain
Q45542 : INF: Shared Access to Modified Data
Q43199 : INF: Concurrency and Consistency and SQL Server Alternatives
Additional query words: Windows NT
Keywords : kbprg SSrvLock SQLFAQ SSrvWinNT
Version : winnt:4.2x
Platform : winnt
Issue type : kbinfo
Last Reviewed: June 9, 1999