You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/relational-databases/sql-server-deadlocks-guide.md
+15-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -475,12 +475,12 @@ The second update statement in **Session A** will be blocked by **Session B** on
475
475
476
476
After a few seconds, the deadlock monitor will identify that the transactions in **Session A** and **Session B** are mutually blocking one another, and that neither can make progress. You should see a deadlock occur, with **Session A** chosen as the deadlock victim. **Session B** will complete successfully. An error message will appear in **Session A** with text similar to the following:
477
477
478
-
```
478
+
```output
479
479
Msg 1205, Level 13, State 51, Line 7
480
480
Transaction (Process ID 51) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
481
481
```
482
482
483
-
If a deadlock is not raised, verify that READ_COMMITTED_SNAPSHOT has been enabled in your sample database. Deadlocks may occur in any database configuration, but this example requires READ_COMMITTED_SNAPSHOT to be enabled.
483
+
If a deadlock is not raised, verify that READ_COMMITTED_SNAPSHOT has been enabled in your sample database. Deadlocks can occur in any database configuration, but this example requires READ_COMMITTED_SNAPSHOT to be enabled.
484
484
485
485
You could then view details of the deadlock in the ring_buffer target of the `system_health` Extended Events session, which is enabled and active by default in SQL Server. Consider the following query:
486
486
@@ -511,7 +511,7 @@ You can view the XML in the `Deadlock_XML` column inside SSMS, by selecting the
[Optimized locking](performance/optimized-locking.md) introduced a different method for locking mechanics that changes how deadlocks involving exclusive TID locks may be reported. Under each resource in the deadlock report's `<resource-list>`, each `<xactlock>` element reports the underlying resources and specific information for locks of each member of a deadlock.
517
517
@@ -532,30 +532,33 @@ In session 1:
532
532
533
533
```sql
534
534
--session 1
535
-
begin tran foo;
536
-
update t2 set b = b+10where a =1;
535
+
BEGIN TRAN foo;
536
+
UPDATE t2 SET b = b+10WHERE a =1;
537
537
```
538
538
539
539
In session 2:
540
+
540
541
```sql
541
542
--session 2:
542
-
begin tran bar
543
-
update t2 set b = b+10where a =2;
543
+
BEGIN TRAN bar
544
+
UPDATE t2 SET b = b+10WHERE a =2;
544
545
```
545
-
546
+
546
547
In session 1:
548
+
547
549
```sql
548
550
--session 1:
549
-
update t2 set b = b +100where a =2;
551
+
UPDATE t2 SET b = b +100WHERE a =2;
550
552
```
551
-
553
+
552
554
In session 2:
555
+
553
556
```sql
554
557
--session 2:
555
-
update t2 set b = b +20where a =1;
558
+
UPDATE t2 SET b = b +20WHERE a =1;
556
559
```
557
560
558
-
This results in a deadlock. In this case, a keylock resource, where each session holds an X lock on its own TID and is waiting on the S lock on the other TID, resulting in a deadlock. The following XML, captured as the deadlock report, contains elements and attributes specific to optimized locking:
561
+
This scenario of competing `UPDATE` statements results in a deadlock. In this case, a keylock resource, where each session holds an X lock on its own TID and is waiting on the S lock on the other TID, resulting in a deadlock. The following XML, captured as the deadlock report, contains elements and attributes specific to optimized locking:
559
562
560
563
:::image type="content" source="media/sql-server-deadlocks-guide/optimized-locking-tid-lock-deadlock-xml.png" alt-text="A screenshot of the XML of a deadlock report showing the UnderlyingResource nodes and keylock nodes specific to optimized locking." lightbox="media/sql-server-deadlocks-guide/optimized-locking-tid-lock-deadlock-xml.png":::
0 commit comments