Re: How can I minimize deadlocks ??

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Tom Moreau (tom_at_dont.spam.me.cips.ca)
Date: 04/19/04


Date: Mon, 19 Apr 2004 15:31:00 -0400

You can do this without a transaction:

update Documents
set
    Available = 0
where
    DocID = (select top 1 DocID from Documents as d
                    where d.Available = 1
                    order by d.DateTimeInserted)

-- 
Tom
---------------------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"Andrei" <anonymous@discussions.microsoft.com> wrote in message
news:A7321096-47A3-463E-A95E-D23012A0752F@microsoft.com...
Hi everyone,
I have an application used by several users. The following logic is
implemented in a stored procedure to make sure that the users are accessing
the next available document and no documents are accessed by more than one
user:
Begin Transaction
Select Top 1 @DocID = doc.DocID
>From Documents With (UpdLock)
Where Available = 1
Order By doc.DateTimeInserted
if @@RowCount  <> 0
Update Documents
Set Available = 0
Where DocID = @DocID
Commit Transaction
This is working fine and I have achieved the goals described above. However
we are experiencing quite a high number of deadlocks. Could somebody tell us
if I can do something to minimize the number of deadlocks?
Thank you in advance.


Relevant Pages

  • Re: Transaction Deadlocks your thoughts?
    ... The rules for minimizing deadlocks are ... you to "soft lock" any resource you need prior to going into transaction ... Wayne Snyder, MCDBA, SQL Server MVP ...
    (microsoft.public.sqlserver.programming)
  • Re: unexpected deadlocks
    ... Right now, you're serializing things, which will ... Columnist, SQL Server Professional ... and COM+ transactions, which force the Sql Server transaction isolation ... This explains the deadlocks. ...
    (microsoft.public.sqlserver.server)
  • Re: Trigger Deadlock
    ... RAISERROR 20000 'trg_myTable_UPDATE Update Trigger Failed. ... COMMIT TRANSACTION ... As for why you are getting deadlocks, ... SQL Server error log. ...
    (comp.databases.ms-sqlserver)
  • Re: Transaction Isolation Level
    ... This means that while I initiate a transaction selecting all new orders it ... My query is executed on a SQL server 2005. ... the isolation level you should use is snapshot isolation. ...
    (comp.databases.ms-sqlserver)
  • Re: Windows Completely Locks Up!! FREEZE
    ... failing to start/run the Distributed Transaction Coordinator. ... Error Specifics: ... The Business Contact Manager SQL Server Startup Service service terminated ... The service did not respond to the start or control request in a timely ...
    (microsoft.public.windowsxp.general)