

There are multiple ways to avoid the Deadlock situations in SQL Server. Exclusive Lock – In case a resource is an exclusive lock, then it can be read as well as written.Shared Lock is used to preventing data from being updated. Shared Lock – It is used for reading data so it is also called a read lock.To achieve this lock operation is used to isolate the transactions. Shared vs Exclusive LockĪ well-optimized SQL Query is written in a manner where one transaction is trying to read the data from a table and no other transactions can update the same data at the same time.
#Sql profiler deadlock how to#
Later, in this article, we will explore How to trace and detect a Deadlock in SQL Server Profile and then we will see the way we can minimize or prevent the Deadlock situation. In the above scenario, the first query window will run successfully, however, the 2nd query window will be in a Deadlock situation and you will get the below output – If you want to increase it, you can set it to10 or 15 seconds delay. Make sure to execute the second query window immediately after executing the first one as the WAITFOR DELAY is 5 seconds. Next, open another query window and execute the below script. Run below query in new query window – BEGIN TRANSACTION

In this case, the Deadlock scenario may occur.īelow SQL Query will help us to generate a Deadlock situation.įirst, we will create 2 Global Temp tables CREATE TABLE #Table1 (

The best example in the SQL server is, 2 transactions are trying to update the same table at the same time. In this case, users may face application performance issues. What is Deadlock?ĭeadlock in SQL server is a scenario where two or more resources are trying to access the same resource which is mutually being locked by each other and now waiting for each other to complete. Let’s start with an introduction to Deadlock.
