Many times we face performance problems specially when we try to query data from tables with thousands or millions of records.
There are many things you can do to improve Query performance (Indexes, Avoid Cursors, have normalized data, etc) but in this post I will only talk about the use of NOLOCK.
So why NOLOCK?
NOLOCK is a nice feature that used in the right situations could improve your query performance significantly, with very little effort.
How it works?
Simply put, MSSQL locks records every time is running a SQL transaction, this could be a simple UPDATE query or an entire background process from a stored procedure, trigger or even a website manipulating data.
By default when you query a table, it waits the exact time until there is nothing locking the data to pull the records to ensure data Integrity (when all the changes have been committed).
But what if you just want to pull the data regardless if the changes are up to date?