|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Saturday, April 06, 2013 12:20 AM
Points: 649,
Visits: 263
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 11:21 AM
Points: 2,163,
Visits: 2,148
|
|
Nice question, thanks.
Though I think formatting the code into little sections, and including the commented select statements, makes it a little more confusing and harder to read than it could have been.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Thursday, May 16, 2013 1:46 PM
Points: 18,732,
Visits: 12,329
|
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Today @ 5:30 AM
Points: 648,
Visits: 1,302
|
|
Just one question. What's the significance of the (nolock) hint? Could you argue that none of the answers could be guaranteed in the event of a dirty read? Cheers and many thanks for the question. GPO

One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important. Bertrand Russell
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Tuesday, February 19, 2013 6:40 AM
Points: 224,
Visits: 636
|
|
Argh didn't get it wrong because I didn't know the answer but rather because I can't seem to count this morining.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 11:51 AM
Points: 5,232,
Visits: 7,023
|
|
Nice question, though maybe a bit too easy.
Shame about the (nolock) hints, though. They serve no purpose, and they might lead people to believe that these hints are okay to use. They are not, except in a very limited amount of situations.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Today @ 1:01 PM
Points: 9,367,
Visits: 6,463
|
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 3:44 PM
Points: 1,786,
Visits: 3,323
|
|
Hugo Kornelis (10/7/2010) and they might lead people to believe that these hints are okay to use. They are not, except in a very limited amount of situations. You won't believe how many people that actually use NOLOCK or READ_UNCOMMITTED to "fix" concurrency and locking problems. One of our vendors use NOLOCK in every(!) SELECT statement in a system we have purchased from them. They have never bothered to explain the reason for doing it, but my guess, after doing some investigation, is that it is caused by two things:
- Lots of missing indexes, which results in excessive scans - Bad programming, because when I save data in the front-end, SQL Profiler showed that before the transaction for the update statement was committed, another connection from my pc was opened trying to read the updated row(s).
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 6:16 AM
Points: 2,862,
Visits: 2,464
|
|
First - this was a very good question. Learned something today which is great.
Hugo Shame about the (nolock) hints, though. They serve no purpose, and they might lead people to believe that these hints are okay to use. They are not, except in a very limited amount of situations.
What would these limited situations be?
Nils You won't believe how many people that actually use NOLOCK or READ_UNCOMMITTED to "fix" concurrency and locking problems. One of our vendors use NOLOCK in every(!) SELECT statement in a system we have purchased from them. They have never bothered to explain the reason for doing it, but my guess, after doing some investigation, is that it is caused by two things:
- Lots of missing indexes, which results in excessive scans - Bad programming, because when I save data in the front-end, SQL Profiler showed that before the transaction for the update statement was committed, another connection from my pc was opened trying to read the updated row(s).
How about thousands of connections hitting against high volume OLTP databases that are also required for up to the minute reporting where replication is not an issue nor are dirty reads?
There are times where hints are required. I may not like them as the norm, but I don't think that one should dismiss them all together.
Steve Jimmo Sr DBA “If we ever forget that we are One Nation Under God, then we will be a Nation gone under." - Ronald Reagan
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 11:51 AM
Points: 5,232,
Visits: 7,023
|
|
sjimmo (10/7/2010)
Hugo Shame about the (nolock) hints, though. They serve no purpose, and they might lead people to believe that these hints are okay to use. They are not, except in a very limited amount of situations. What would these limited situations be? Mostly queries that report aggregated data for an audience that doesn't care about the exact number, but only wants an indication. If the numbers my query produces will be rounded to the nearest million dollars anyway, I can live with a result that might be a couple of thousand dollars off.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|