0

I've read about this and transaction isolation level and was just wondering.....

I have some queries that query against products, categories, locations & stock. Now the products, categories and locations data rarely changes, but as you can imagine, stock does. Is it reasonable to specify WITH (NOLOCK) on products, categories, locations but not specify it on Stock? I've done some timings and it does seem to improve performance so I'm cautiously happy.

My understanding is that if I don't specify WITH (NOLOCK) on Stock, that should only get committed transactions and not have dirty reads. Whilst, as the other tables contents rarely change, it's safe to specify WITH (NOLOCK).

The specific proc I am working on doesn't write to any of the mentioned tables....it puts some results into a #table and returns rows from that.

Your thoughts appreciated.

2
  • 1
    Personally, I would not use NOLOCK to improve performance. Index and query tuning is most often the best way to improve performance. Commented Nov 3, 2017 at 10:17
  • I hear you Dan, but sometimes we can only alter what we can control ;) I get the pros and cons...in the case mentioned, it's quick, easy and safe given the usage of the tabkles involved. Long term, you are correct, but for now... Commented Nov 3, 2017 at 10:37

1 Answer 1

1

With NOLOCK put only lock Sch-S (schema stability)

Without NOLOCK S lock + Sch-S But NOLOCK give READ UNCOMMITTED data (dirty reads) which will give you incorrect data.

https://sqlstudies.com/2015/03/18/why-not-nolock/

Use RSCI (Read Committed Snapshot Isolation) row-versioning implementation of the read committed isolation level https://sqlperformance.com/2014/05/t-sql-queries/read-committed-snapshot-isolation

Sign up to request clarification or add additional context in comments.

5 Comments

Nice article Tapakah, but am I correct in what I said about not specifying the hint on the Stock table?
Yep, only table with hint return uncommitted data
Little steps. I think I can make my changes quite safely at a sproc level without impacting anything else. Regarding snapshot isolation level, that could be a meeting with the DBAs. Thanks for the info & have a great weekend.
I think you mean Sch-S (schema stability) lock. A Schema modification lock is effectively an exclusive lock on the database object.
Ops, sure Sch-S :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.