Solved

WITH (nolock) vs nolock ??

Posted on 2008-10-28
6
1,483 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
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 250 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 59

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 250 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
Viewers will learn how the fundamental information of how to create a table.

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now