Solved

WITH (nolock) vs nolock ??

Posted on 2008-10-28
6
1,492 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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need sql in string 2 29
SQL Select Query help 1 37
sql server cross db update 2 20
SQL - Error "The Multi-Part Identifier could not be found" 2 19
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

756 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