Can NoLock be used on table-returning functions?

  • I'm trying to use NoLock in my code, and it keeps barking back at me.

    I the code uses table returning functions except down at the very bottom level.

    Must NoLock be used only on a query selecting from a table, or can it be on a table-returning function?

  • ...Must NoLock be used only on a query selecting from a table, or can it be on a table-returning function?

    You better not to use NoLock at all.

    What is your reason behind using it? What are you trying to achieve?

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Reason I want to use NoLock is because queries are returning slowly. Instructions say that is what it is good for.

    This is on a reporting database, not a transactional database, though there are datadumps on a daily basis, pulling fresh data in. but only at prescribed times, not all day long.

  • nonghead-webspam (7/1/2014)


    Reason I want to use NoLock is because queries are returning slowly. Instructions say that is what it is good for.

    This is on a reporting database, not a transactional database, though there are datadumps on a daily basis, pulling fresh data in. but only at prescribed times, not all day long.

    I wonder where did you found this instructions from. You should stick it to the closest rubbish bin you can find.

    NoLock is not the method to improve the query performance - it is a road to return really dirty data. It may not return data which exists in a table, and it may return data which is not already there...

    It has nothing to do what type of database you are working on.

    If you investigate and "google" :-), you will find a lot of material on this subject. One of the MSDN one which I recommend to read first:

    http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • nonghead-webspam (7/1/2014)


    Reason I want to use NoLock is because queries are returning slowly. Instructions say that is what it is good for.

    No.

    Nolock is not a performance tuning technique. It's not there to make your queries faster and, if you have a DB that's static, it's going to have just about no effect.

    Rather learn to tune your queries properly than flailing around randomly looking for a magic silver bullet that doesn't exist.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thank you both for your prickly, opinionated responses, which......uh.....were right on the money, and I followed your advice and solved the problem another way.

    Thanks, sincerely.

    BTW, the answer to my question seems to be that "with (NoLock)" must be applied at the table level, and doesn't work with table returning functions.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply