Use of NOLOCK in sql server query?

Forums SQLUse of NOLOCK in sql server query?
Staff asked 3 years ago

Answers (2)

Add Answer
Mihir Shah Marked As Accepted
Staff answered 3 years ago

In simple terms, Nolock means we are instructing SQL to do not keep on any kind of Lock on given table(s) and return whatever data are available. No matter whether data are committed or non-committed.

In other words, consider the scenario where multiple users are performing operations on same table. For example, user1 is performing DML operation (insert/update/delete) on table XYZ and user2 is performing DQL (select) on table XYZ. Yet data are not committed into table XYZ by his/her DML operation still user2 will get those RAW data as query results just because of NOLOCK.

Simply NOLOCK will returns all data available at that query moment. It is mostly useful for Non-Banking applications but if Banking applications where we apply the NOLOCK and suppose due to some errors transactions gets rollback then that RAW data will be harmful for us because actually those data are not committed into table but still we are using in our operation(s) using NOLOCK.

Hope, this answer will help.

Staff answered 3 years ago

You can use it when you’re only reading data, and you don’t really care about whether or not you might be getting back data that is not committed yet.

It can be faster on a read operation, but I cannot really say by how much.

Another definition

When you use the NOLOCK query hint you are telling the storage engine that you want to access the data no matter if the data is locked by another process or not.

Subscribe

Select Categories