sql server 2012

hi,
Is adviciable to use nolock function in select query?

what is the diff of nolock and with (nolock)
kowsika deviAsked:
Who is Participating?
 
Pawan KumarConnect With a Mentor Database ExpertCommented:
>>to avoid deadlock we can use otherwise it should not use is it correct jj
When you use NOLOCK  there is no guarantee that a deadlock will not occur. You need to optimize your query.
0
 
ste5anSenior DeveloperCommented:
You should use NOLOCK only when it is unimportant whether the results are correct or not.

Cause NOLOCK can lead to return not (longer) existing data or to not return existing data. And there is no way for you to be sure..
0
 
Pawan KumarDatabase ExpertCommented:
Is adviciable to use nolock function in select query?
it depends.

WITH(NOLOCK)
It is equal to using READ UNCOMMITED as a transaction isolation level. So, you stand the risk of reading an uncommitted row that is subsequently rolled back, i.e. data that never made it into the database. So, while it can prevent reads being deadlocked by other operations, it comes with a risk. Basically you can get dirty reads. REF WITH(NOLOCK) - Does not improve performance. WITH(NOLOCK) is NOT by default.

Read more from -
https://www.mssqltips.com/sqlservertip/2470/understanding-the-sql-server-nolock-hint/
http://blogs.sqlsentry.com/aaronbertrand/bad-habits-nolock-everywhere/

With lock is by default and you do not have to specify anything for this.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
kowsika deviAuthor Commented:
to avoid deadlock we can use otherwise it should not use is it correct jj
0
 
kowsika deviAuthor Commented:
thanks jj
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Note to self:  Make one of those 'Worlds's Most Interesting Man' memes where the top says something like 'I don't always SELECT large sets in production databases', and the bottom says 'But when I do I use WITH(NOLOCK) and SET TRANSACTION LEVEL LOW'.
0
 
ste5anSenior DeveloperCommented:
Na, I only use NOLOCK to make queries faster.. ya 'now, no locking and that overhead transaction isolation voodoo.. :)

You won't believe how often I've seen NOLOCK used as "improved query performance"..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.