Solved

WITH (nolock) vs nolock ??

Posted on 2008-10-28
6
1,487 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I have a large data set and a SSIS package. How can I load this file in multi threading?
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
Via a live example, show how to shrink a transaction log file down to a reasonable size.

810 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