---------------Create Tabletmp1 (IDint Primary Key, namenvarchar( -))-----------Insert intoTMP1 (Id,name)Values(1,'Zhsan1');Insert intoTMP1 (Id,name)Values(2,'LISI1');-------------------------------Select * fromTmp1
UPDATE statement locks the database
-- --------------------------- begin Tran tran1 Update Set name='zhsan'where id=1 -- ----------------------------- Select * from TMP1
The query has been in progress, and the table is locked.
-- ----------------------------- Update Set name='Lisi'where id=2-- ----------------------------- Select * from where Id>1
-- ----------------------------- Delete from where id=2-------------------------------Select* fromwhere ID>1
Query, update, delete the row of data except the lock can be successful, indicating that only the id=1 of the locked row, the other rows of the query, update and delete no impact
Insert statement
-- ----------------------------- Insert into Values (3,'Lisi') -- ----------------------------- Select * from where ID>1
Successful execution of the results, indicating that the insert is not affected
First restore the database to
-- --------------------------- begin Tran tran1 Update Set name='zhsan'where id=1
With (Readpast) and with (NOLOCK)
-- ----------------------------- Select * from with (Readpast)
-- ----------------------------- Select * from with (NOLOCK)
With (Readpast) ignores the locked line, with (NOLOCK) does not
SQL with (NoLock), with (ReadPast)