SQL Server Profiler traces deadlocks

Source: Internet
Author: User

An important application scenario for SQL Server Profiler is to monitor the analysis deadlock.

Here's an example to learn how profiler monitors deadlocks.

1. Create test data to simulate deadlocks, create tables table_a and table_b , and insert test data.

CREATE TABLEtable_a (IDint, Numint)CREATE TABLETable_b (IDint, Numint)INSERT  intoTable_aVALUES(1, -)INSERT  intoTable_aVALUES(2, -)INSERT  intoTable_bVALUES(3, at)INSERT  intoTable_bVALUES(4, +)

2. Open the SQL Server Profiler, create a new trace to monitor the deadlock, select the events to monitor in the event selection, run the trace:

3. Create a new two query window and follow the steps to execute the statement.

 --  query window 1   transaction  -- step 1  update  table_a set  num Span style= "color: #808080;" >=  55  where  ID =  1  -- step 1  select  *  from  table_b -- step 3  commit  transaction  

 

 --  query window 2   transaction  -- step 2  update  table_b set  num Span style= "color: #808080;" >=  66  where  ID =  4  -- step 2  select  *  from  table_a -- step 4  commit  transaction  

4. After you execute step 4, a deadlock occurs, but there is only one error message that is not too detailed.

5. Back to the profiler interface, select Deadlock graph, you can see more detailed deadlock reasons, the mouse on the ellipse can also display the deadlock statement, through which we can quickly and accurately find the cause of the deadlock.

SQL Server Profiler traces deadlocks

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.