Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UPDATE using locking hint

Status
Not open for further replies.

mkal

Programmer
Jun 24, 2003
223
US
I've inherited an application that calls a number of stored procedures. In quite a few of them I've been finding updates that look like the following:

UPDATE tbl_name
SET field_name = 'some value'
FROM tbl_name WITH (NOLOCK)
WHERE field_name = 'some other value'

I didn't think you could use the "WITH (NOLOCK)" hint when UPDATING,DELETTING or INSERTING.

Should the UPDATE be re-written to:

UPDATE tbl_name
SET field_name = 'some value'
WHERE field_name = 'some other value'

or can I just ignore it?

 
Looks like this hint just ignored - no error is generated.

However, it may make sense to re-write without it, since BOL states

WITH ( <Table_Hint_Limited> )
Specifies one or more table hints that are allowed for a target table. The WITH keyword and the parentheses are required. NOLOCK and READUNCOMMITTED are not allowed. For information about table hints, see Table Hints (Transact-SQL).

for the UPDATE command.
 
Figured as much, nice to have some confirmation. I'll probably pull it out.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top