?
Solved

WITH (nolock) vs nolock ??

Posted on 2008-10-28
6
Medium Priority
?
1,500 Views
Last Modified: 2012-08-13
I read somewhere that starting SQL server 2005 the nolock hint will not work by itself, but you will need to add 'with nolock'.
Can someone point me to the Microsoft article that mentions this.

Thanks!
0
Comment
Question by:sbagireddi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 22824141
I think I had read that before, but I've been using 2005 for quite some time now and NOLOCK works fine

select * from tablename (nolock)
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 1000 total points
ID: 22824179
Excerpt from:
http://msdn.microsoft.com/en-us/library/ms187373(SQL.90).aspx


In SQL Server 2005, with some exceptions, table hints are supported in the FROM clause only when the hints are specified with the WITH keyword. Table hints also must be specified with parentheses.

The following table hints are allowed with and without the WITH keyword: NOLOCK, READUNCOMMITTED, UPDLOCK, REPEATABLEREAD, SERIALIZABLE, READCOMMITTED, FASTFIRSTROW, TABLOCK, TABLOCKX, PAGLOCK, ROWLOCK, NOWAIT, READPAST, XLOCK, and NOEXPAND. When these table hints are specified without the WITH keyword, the hints should be specified alone. For example:

FROM t (FASTFIRSTROW)
When the hint is specified with another option, the hint must be specified with the WITH keyword:

FROM t WITH (FASTFIRSTROW, INDEX(myindex))
The restrictions apply when the hints are used in queries against databases with the compatibility level of 90.
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22824257
Agree with Tim and Brandon, I have used both ways without issue.  When you use the hint in views or other areas where the SQL is changed on save, you will see that when you go back in it now says WITH (NOLOCK). ;)
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 8

Author Comment

by:sbagireddi
ID: 22824293
I am going to upgrade our servers from sql server 2000 to 2008 and have tons of stored procs missing the 'with' keyword.
i read somewhere that sql server 2008 completely ignores the hint when "with" is not specified.
0
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 1000 total points
ID: 22824363
I think you're fine....
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22824444
SQL 2008 BOL on Table hints:
http://msdn.microsoft.com/en-us/library/ms187373.aspx

Omitting the WITH keyword is a deprecated feature: This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question