Select with (nolock)
source link: https://www.codesd.com/item/select-with-nolock.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Select with (nolock)
My boss keeps on forcing me to write SELECT queries with with (nolock)
to prevent deadlocks. But AFAIK, Select statements by default does not have locks, so selecting with with (nolock)
and selecting without doesn't make any difference. Please correct me if I am wrong.
The two queries:
SELECT * from EMP with (nolock)
SELECT * from EMP
Isn't both are same. If I don't put nolock will it be prone to deadlocks? Please tell me what should I use.
Nolocks should be used with extreme caution. The most common understanding of nolock (read uncommitted) hint is that it reads data that has not been committed yet. However, there are other side effects that can be very dangerous. (search for "nolock" and "page splits")
There's a really good write up here... http://sqlmag.com/sql-server/beware-nolock-hint
In short, "nolocking"ing everything is not always a good idea... if ever.
Related Articles
Is a reading of the overwritten values prevented when SELECT WITH (NOLOCK)?
SELECT for a long UPDATE - What happens to SELECT for different levels of transaction isolation and SELECT WITH (NOLOCK)?
Is it OK to set WITH (NOLOCK, READUNCOMMITTED) in the update block in the select statement?
Using WITH (NOLOCK) to increase performance
How to use WITH (NOLOCK) in the query with JOIN
SQL-Server-2005: Why are the results returned in a different order with (nolock)
With (nolock) or (nolock) - Is there a difference?
Syntax WITH (NOLOCK) for the subquery
SQL server selector query with NOLOCK not working
SQL Server Inner Join using WITH (NOLOCK)
Find the total number of rows in the query Select with order by
Drag and Drop multiple select with options
JQuery imgAreaSelect defines the initial selection with the aspect ratio
Angular2 select with ngModel is empty (driven model)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK