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
@@ -118,17 +118,17 @@ Learn more about each of these approaches in the [Prevent a deadlock from reoccu
118
118
119
119
In this article, we use the `AdventureWorksLT` sample database to set up alerts for deadlocks, cause an example deadlock, analyze the deadlock graph for the example deadlock, and test changes to prevent the deadlock from reoccurring.
120
120
121
-
We use the [SQL Server Management Studio](/sql/ssms/download-sql-server-management-studio-ssms) (SSMS) client in this article, as it contains functionality to display deadlock graphs in an interactive visual mode. You can use other clients such as [Azure Data Studio](/azure-data-studio/download-azure-data-studio), the [MSSQL extension for Visual Studio Code](/sql/tools/visual-studio-code-extensions/mssql/mssql-extension-visual-studio-code), [sqlcmd](/sql/tools/sqlcmd/sqlcmd-utility), or your favorite T-SQL querying tool to follow along with the examples, but you might only be able to view deadlock graphs as XML.
121
+
We use the [SQL Server Management Studio](/ssms/install/install) (SSMS) client in this article, as it contains functionality to display deadlock graphs in an interactive visual mode. You can use other clients such as the [MSSQL extension for Visual Studio Code](/sql/tools/visual-studio-code-extensions/mssql/mssql-extension-visual-studio-code), [sqlcmd](/sql/tools/sqlcmd/sqlcmd-utility), or your favorite Transact-SQL querying tool to follow along with the examples, but you might only be able to view deadlock graphs as XML.
122
122
123
123
### Create the AdventureWorksLT database
124
124
125
125
To follow along with the examples, create a new database in Azure SQL Database and select **Sample** data as the **Data source**.
126
126
127
-
For detailed instructions on how to create `AdventureWorksLT` with the Azure portal, Azure CLI, or PowerShell, select the approach of your choice in [Quickstart: Create an Azure SQL Database single database](single-database-create-quickstart.md).
127
+
For detailed instructions on how to create `AdventureWorksLT` with the Azure portal, Azure CLI, or PowerShell, select the approach of your choice in [Quickstart: Create a single database in Azure SQL Database](single-database-create-quickstart.md).
128
128
129
129
### Set up deadlock alerts in the Azure portal
130
130
131
-
To set up alerts for deadlock events, follow the steps in the article [Create alerts for Azure SQL Database using the Azure portal](alerts-create.md).
131
+
To set up alerts for deadlock events, follow the steps in the article [Create alerts for Azure SQL Database and Azure Synapse Analytics using the Azure portal](alerts-create.md).
132
132
133
133
Select **Deadlocks** as the signal name for the alert. Configure the **Action group** to notify you using the method of your choice, such as the **Email/SMS/Push/Voice** action type.
134
134
@@ -184,7 +184,7 @@ To create an XEvents session that writes to an event file target, we:
184
184
To configure an Azure Storage container, first create or select an existing Azure Storage account, then create the container. Generate a Shared Access Signature (SAS) token for the container. This section describes completing this process in the Azure portal.
185
185
186
186
> [!NOTE]
187
-
> If you wish to create and configure the Azure Storage blob container with PowerShell, see [Event File target code for extended events in Azure SQL Database and SQL database in Fabric](xevent-code-event-file.md). Alternately, you might find it convenient to [Use Azure Storage Explorer](#use-azure-storage-explorer) to create and configure the Azure Storage blob container instead of using the Azure portal.
187
+
> If you wish to create and configure the Azure Storage blob container with PowerShell, see [Create an event session with an event_file target in Azure Storage](xevent-code-event-file.md). Alternately, you might find it convenient to [Use Azure Storage Explorer](#use-azure-storage-explorer) to create and configure the Azure Storage blob container instead of using the Azure portal.
188
188
189
189
#### Create or select an Azure Storage account
190
190
@@ -206,7 +206,7 @@ From the storage account page in the Azure portal:
206
206
1. Select **+ Container** to create a new container. The New container pane appears.
207
207
1. Enter a name for the container under **Name**.
208
208
1. Select **Create**.
209
-
1. Select the container from the list after it is created.
209
+
1. Select the container from the list after it's created.
210
210
211
211
#### Create a shared access token
212
212
@@ -294,69 +294,9 @@ GO
294
294
295
295
---
296
296
297
-
## Cause a deadlock in AdventureWorksLT
298
-
299
-
> [!NOTE]
300
-
> This example works in the `AdventureWorksLT` database with the default schema and data when RCSI is enabled. See [Create the AdventureWorksLT database](#create-the-adventureworkslt-database) for instructions to create the database.
301
-
302
-
To cause a deadlock, you need to connect two sessions to the `AdventureWorksLT` database. We refer to these sessions as **Session A** and **Session B**.
303
-
304
-
In **Session A**, run the following Transact-SQL. This code begins an [explicit transaction](/sql/relational-databases/sql-server-transaction-locking-and-row-versioning-guide#starting-transactions) and runs a single statement that updates the `SalesLT.Product` table. To do this, the transaction acquires an [update (U) lock](/sql/relational-databases/sql-server-transaction-locking-and-row-versioning-guide#behavior-when-modifying-data) on one row on table `SalesLT.Product` which is converted to an exclusive (X) lock. We leave the transaction open.
305
-
306
-
```sql
307
-
BEGIN TRANSACTION;
308
-
309
-
UPDATESalesLT.Product
310
-
SET SellEndDate = SellEndDate +1
311
-
WHERE Color ='Red';
312
-
```
313
-
314
-
Now, in **Session B**, run the following Transact-SQL. This code doesn't explicitly begin a transaction. Instead, it operates in [autocommit transaction mode](/sql/relational-databases/sql-server-transaction-locking-and-row-versioning-guide#starting-transactions). This statement updates the `SalesLT.ProductDescription` table. The update takes out an update (U) lock on 72 rows on the `SalesLT.ProductDescription` table. The query joins to other tables, including the `SalesLT.Product` table.
To complete this update, **Session B** needs a shared (S) lock on rows on the table `SalesLT.Product`, including the row that is locked by **Session A**. **Session B** is blocked on `SalesLT.Product`.
330
-
331
-
Return to **Session A**. Run the following Transact-SQL statement. This runs a second `UPDATE` statement as part of the open transaction.
The second update statement in **Session A** is blocked by **Session B** on the `SalesLT.ProductDescription`.
347
-
348
-
**Session A** and **Session B** are now mutually blocking one another. Neither transaction can proceed, as they each need a resource that is locked by the other.
349
-
350
-
After a few seconds, the deadlock monitor identifies 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. An error message appears in **Session A** with text similar to the following:
351
-
352
-
```output
353
-
Msg 1205, Level 13, State 51, Line 7
354
-
Transaction (Process ID 91) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
355
-
```
356
-
357
-
**Session B** completes successfully.
297
+
## Cause a deadlock
358
298
359
-
If you [set up deadlock alerts in the Azure portal](#set-up-deadlock-alerts-in-the-azure-portal), you should receive a notification shortly after the deadlock occurs.
299
+
Because [optimized locking](/sql/relational-databases/performance/optimized-locking) is always enabled in Azure SQL Database and SQL database in Fabric, deadlocks are less likely. For more information, and for an example of a deadlock that can occur with optimized locking, see [Optimized locking and deadlocks](/sql/relational-databases/sql-server-deadlocks-guide#optimized-locking-and-deadlocks).
0 commit comments