Possible Duplicate:
SQL Server NOLOCK keyword
What is the difference between these sql queries?
-
SQL query:
SELECT U.ID_USER AS ID, U.USERNAME AS NICK, U.PASSWORD AS PASS FROM T_USERS AS U WITH (NOLOCK) -
SQL query:
SELECT U.ID_USER AS ID, U.USERNAME AS NICK, U.PASSWORD AS PASS FROM T_USERS AS U
First one (query with nolock) will not be blocked even if the data it is reading is locked exclusively and could return the rows which are not yet commited. If reading uncommitted data is not issue then NOLOCK is sually used to reduce blocking. Nolock specify that when reading the data do not try to take locks on resources like table,row,page.
The second one(query without nolock) will be blocked if any of rows are going under modifications or are locked exclusively.It will never read the data which is not yet commited as it will be blocked by the process which is changing the data. This is ususally when you do not want to read the data which is uncommited and where accuracy is of utmost importance.