EnjoY | Database Research And Development: SQL Server: T-SQL script to generate a DeadLock in a Database

Wednesday, August 26, 2020

SQL Server: T-SQL script to generate a DeadLock in a Database

 The DeadLock in a database system is a common thing and all Database Administrators are responsible for detecting and managing a DeadLocks.

In this post, I am sharing T-SQL script to generate a DeadLock situation in a SQL Server.

Most of the time, we are facing DeadLock problem in our Production Database Server.
But What happens, when Database Administrator wants to generate DeadLock situation and intends to create a script for detecting a DeadLock.

First, create two tables with sample data:

Step 1: Open first connection and Execute below query.

Step 2: Open second connection and Execute below queries.

Step 3: Execute below query in first connection again.

Up to Step 2, you can find that queries are running and waiting to complete Step 1. Here, Step 1 became a blocker step for Step 2.

Once you execute the query of Step 3 on first connection, you will get DeadLock situation and will get the message.

No comments:

Post a Comment

It’s all about friendly conversation here at small review :) I’d love to be hear your thoughts!

Be sure to check back again because I do make every effort to reply to your comments here.

Featured Post

SQL Server : SELECT all columns to be good or bad in database system

This article is half-done without your Comment! *** Please share your thoughts via Comment *** In this post, I am going to write about one o...

Popular Posts