Saturday, September 20, 2008

SQL 2005 Table Lock Hint Syntax Change

Syntax for locking tables has been changed in SQL 2005 which makes placing the ‘WITH’ keyword in parentheses illegal.

The following was acceptable in SQL 2000; however, no longer is the case with 2005.
The following is true for SQL 2005:

WRONG
UPDATE Products (WITH NOLOCK) 
SET Name = 'Cheetos'
WHERE ProductCat = 'JunkFood'




CORRECT
UPDATE Products WITH (NOLOCK) 
SET Name = 'Cheetos'
WHERE ProductCat = 'JunkFood'

No comments: