I have a stored procedure which updates a few tables like this:
CREATE PROCEDURE SP_UpdateSomeTables
@bundleId bigint,
@wfStage tinyint
AS
SET XACT_ABORT ON
SET NOCOUNT ON
BEGIN TRANSACTION
UPDATE
table1
SET
[LastUpdated] = GETDATE(),
[WorkflowStage] = @wfStage
WHERE
[Id] = @bundleId
UPDATE
table2
SET
[LastModified] = GETDATE(),
[WorkflowStage] = @wfStage
WHERE
[ResultBundleId] = @bundleId AND
[IsCancelled] = 0
COMMIT TRANSACTION
GO
I'm getting the following error:
Transaction (Process ID 69) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
There are other SELECT queries running parallel on the same set of tables.
How can I avoid the deadlock?
sp_
prefix is reserved, by Microsoft, for Special Procedures. It should not be used for User Stored Procedures names. Using the prefix comes at a performance cost and could result in your Procedure simply not working after an update or upgrade. This is also warned in the documentation. – Larnu