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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
kowsika deviAuthor Commented:
to avoid deadlock we can use otherwise it should not use is it correct jj
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

Pawan KumarDatabase 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.