SQL with (NoLock), with (ReadPast)

Source: Internet
Author: User

---------------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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.