quarta-feira, 25 de abril de 2018

How to cause a deadlock on SQL Server on purpose

Hi!

What I really needed was an error with the word deadlock inside of the message, so this is what I did.
Whenever I need a deadlock to raise up I execute my procedure proc_deadlock.
Then I make my code treatment based on the message that contains the word deadlock.


USE [master]
GO

/****** Object:  StoredProcedure [dbo].[proc_deadlock]    Script Date: 25/04/2018 12:47:19 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

create procedure [dbo].[proc_deadlock]
as

    -- RAISERROR with severity 11-19 will cause execution to 
    -- jump to the CATCH block. 
    RAISERROR ('this is my deadlock', -- Message text. 
               16, -- Severity. 
               1 -- State. 
               ); 

GO


Nenhum comentário:

Postar um comentário