UPDLOCK can reduce the chance of deadlocks but at the expense of concurrent
operations. Although you might view fast response time as performance, I
think it's better to distinguish between performance (query/index tuning)
and concurrency (blocking, deadlocking) so you can address the underlying
causes. Performance and concurrency are closely related, though; the faster
queries run, the less likely you will run into concurrency problems . Of
course, you'll ultimately need to address both for the best response time.
[quoted text, click to view] > Do you recommend UPDLOCK, READPAST to improve performance?
Did you examine the execution plans for scans? Are the delete statements
run as part of a transaction? UPDLOCK is ok but I would be wary of using
READPAST except in special situations.
--
Hope this helps.
Dan Guzman
SQL Server MVP
[quoted text, click to view] "morphius" <morphius@discussions.microsoft.com> wrote in message
news:3C7A531D-CD07-44BA-A782-ECA299EFBE69@microsoft.com...
> Hi Dan,
> I've used the UPDLOCK and it prevented the deadlocks, however it slowed
> down
> the SP it takes a while to finish but it works. Do you recommend UPDLOCK,
> READPAST to improve performance?
> Thank you!
>
> "Dan Guzman" wrote:
>
>> > The PADLOCK hint
>>
>> Sorry, should be UPDLOCK. Damn spell checker :-)
>>
>> --
>> Hope this helps.
>>
>> Dan Guzman
>> SQL Server MVP
>>
>> "Dan Guzman" <guzmanda@nospam-online.sbcglobal.net> wrote in message
>> news:1F917170-D039-4C95-9D14-5E3DE97F3FE9@microsoft.com...
>> >> 1. should i add (nolock) within the select statement? ex: Select empid
>> >> from
>> >> tbl_location WITH (NOLOCK)
>> >
>> > Only if it's acceptable to accidentally delete the wrong data or skip
>> > data
>> > that should be deleted.
>> >
>> >> 2. should i add (updlock) within the delete statement? ex: Delete from
>> >> tbl_employees WITH (UPDLOCK)
>> >
>> > Since you have no explicit transaction (at least in your post), each
>> > delete statement is in an independent atomic transaction. The PADLOCK
>> > hint has little value in that case. A UPDLOCK, HOLDLOCK hint might be
>> > appropriate in your SELECT subqueries if you have an explicit
>> > transaction
>> > and the row is subsequently deleted.
>> >
>> > In addition to Uri's suggestion about the delete order, I suggest you
>> > review the execution plans to avoid scans and tune indexes/queries
>> > accordingly. Scans greatly increase deadlock likelihood because more
>> > rows
>> > are accessed than needed and the performance hit results in more
>> > concurrent queries.
>> >
>> > --
>> > Hope this helps.
>> >
>> > Dan Guzman
>> > SQL Server MVP
>> >
>> > "morphius" <morphius@discussions.microsoft.com> wrote in message
>> > news:79328F46-6C5E-4424-A29F-275654225E5E@microsoft.com...
>> >> Trace 1204 has narrowed the cause of deadlock to these delete
>> >> statements.
>> >> There are a total of 10 delete statements in this SP.
>> >>
>> >> create procedure del_emp @empid int
>> >>
>> >> Delete from tbl_employees
>> >> where empid in (Select empid from tbl_location where empid = @empid)
>> >>
>> >> Delete from tbl_management
>> >> where mge_ID in (Select mge_ID from tbl_sunmanagement where empid =
>> >> @empid)
>> >>
>> >> ........
>> >> ........
>> >>
>> >> Questions:
>> >> 1. should i add (nolock) within the select statement? ex: Select empid
>> >> from
>> >> tbl_location WITH (NOLOCK)
>> >> 2. should i add (updlock) within the delete statement? ex: Delete from
>> >> tbl_employees WITH (UPDLOCK)
>> >>
>> >> Any suggestions highly appreciated.
>> >>
>> >>
>> >>
>> >
>>