sql when using nolock

3

In a query made with two tables, there is the possibility of placing a nolock. Why is this done?

FROM tabla1 t1 (nolock) INNER JOIN tabla2 t2

    
asked by ARG RG 18.06.2016 в 16:36
source

1 answer

9

The NOLOCK table suggestion (or its READUNCOMMITTED equivalent) allows you to perform data readings even if they are blocked by data update instructions.

When a data update instruction is performed (INSERT, DELETE, UPDATE) this data is blocked by SQL Server until the update instruction completes (or the transaction if the instruction is within one). If you try to execute a read instruction it will wait until the data is unlocked and then perform the reading and return the data.

When using NOLOCK, the reading does not wait for the data to be unlocked, reading the data as it is and returning it. This increases the response speed of the queries but also decreases the reliability of the data.

The query might return an updated data for a change that is then thrown back by a ROLLBACK statement.

Therefore you can use NOLOCK when you want to speed up queries in which the reliability of the returned data is not critical.

    
answered by 18.06.2016 / 17:13
source