Solved

WITH (nolock) vs nolock ??

Posted on 2008-10-28
6
1,480 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 8

Author Comment

by:sbagireddi
Comment Utility
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
Comment Utility
I think you're fine....
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
Comment Utility
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

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…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

772 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

11 Experts available now in Live!

Get 1:1 Help Now