SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Just a random observation with 'WITH'


Just a random observation with 'WITH'

Author
Message
Shadab Shah
Shadab Shah
SSC Eights!
SSC Eights! (879 reputation)SSC Eights! (879 reputation)SSC Eights! (879 reputation)SSC Eights! (879 reputation)SSC Eights! (879 reputation)SSC Eights! (879 reputation)SSC Eights! (879 reputation)SSC Eights! (879 reputation)

Group: General Forum Members
Points: 879 Visits: 798
Following is my observation with 'WITH'

I executed the below query
SELECT * FROM Sales.SalesOrderDetail (NOLOCK)


Which run sucessfully

now i execute the below query
UPDATE Sales.SalesOrderDetail_BACKUP (ROWLOCK)
SET UNITPRICE=1
WHERE PRODUCTID=707


(I know the query does not make sense but just a trail)

It gives me the error as
Incorrect syntax near '('.

If i change it to
UPDATE Sales.SalesOrderDetail_BACKUP WITH(ROWLOCK)
SET UNITPRICE=1
WHERE PRODUCTID=707



It Works. Just out of curiosity i would like to know why is WITH not mandatory with (NOLOCK).
Jason-299789
Jason-299789
SSCarpal Tunnel
SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)

Group: General Forum Members
Points: 4763 Visits: 3232
I believe that MS have stated that all hints will require the WITH statement in future to make it consistent.

You shouldn't be using the WITH (NOLOCK) hint It can have some chaotic effects.

_________________________________________________________________________
SSC Guide to Posting and Best Practices
Lowell
Lowell
SSC Guru
SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)

Group: General Forum Members
Points: 68811 Visits: 40905
a nolock on an update is ignored anyway, so there's no advantage to adding it anyway.

only SELECT statements will honor NOLOCK, and then you get the usual possibilities about doubled/repeated data, missing data, and data that is returned but doesn't exist any more.

Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search