/microsoft-sql-vscode:deadlock-analysis-azuresqlfrom Microsoft SQL for Visual Studio Code
Analyzes deadlock reports and history on Azure SQL Database or Fabric SQL Database. Provides T-SQL queries for active deadlock extended events sessions and deadlock graph retrieval.
Ships in Microsoft SQL for Visual Studio Code. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
For a request to set up a future capture (especially over hours or days), load create-xe-session for session design, attribution actions, durable storage, bounded retention and capture verification. Return here to interpret the resulting deadlock graphs. The capture examples below are starting points: successful CREATE/START alone does not prove useful events were recorded, and event-level actions must not be confused with attribution for every participant in a deadlock graph.
Use this skill when the user asks about deadlocks, deadlock reports, or deadlock history on Azure SQL Database or Fabric SQL Database.
Platform Guard: This skill targets Engine Edition 5 (Azure SQL DB) or 11 (Fabric SQL DB). If the connected database is SQL Server (Engine Edition 1–4) or Managed Instance (Engine Edition 8), use read-only SQL Server deadlock graph analysis using the host SQL tools instead.
microsoft-sql-admin plugin (mssql_list_database_connections,
mssql_connect_database, then mssql_execute_query); any other SQL tool the agent host provides for
running T-SQL and reading result sets;
sqlcmd from a terminal. If the SQL
Tools MCP server is not connected or lists no connections, follow the SQL tools of the Visual Studio Code MSSQL extension; this plugin does not ship the standalone SQL Tools MCP server,
which asks before installing or configuring anything. If no SQL tool can be made available, give the
user the T-SQL to run and ask for the results.VIEW SERVER PERFORMANCE STATE (VIEW SERVER STATE before SQL Server 2022) or, on Azure
SQL Database, VIEW DATABASE PERFORMANCE STATE or ##MS_ServerStateReader##, plus any other read
permission these queries need. A tool is only as read-only as the login it connects with.SELECT
es.name AS [Session Name],
des.create_time AS [Created],
CASE WHEN des.address IS NOT NULL THEN 'Running' ELSE 'Stopped' END AS [Status],
det.target_name AS [Target Type]
FROM sys.database_event_sessions AS es
LEFT JOIN sys.dm_xe_database_sessions AS des
ON es.name = des.name
LEFT JOIN sys.dm_xe_database_session_targets AS det
ON des.address = det.event_session_address
WHERE es.name LIKE '%deadlock%';
SELECT
cntr_value AS cumulative_deadlock_count
FROM sys.dm_os_performance_counters
WHERE counter_name = 'Number of Deadlocks/sec'
AND instance_name = '_Total';
DECLARE @tracename AS sysname = N'deadlocks';
WITH ring_buffer
AS (SELECT CAST (target_data AS XML) AS rb
FROM sys.dm_xe_database_sessions AS s
INNER JOIN sys.dm_xe_database_session_targets AS t
ON CAST (t.event_session_address AS BINARY (8)) = CAST (s.address AS BINARY (8))
WHERE s.name = @tracename
AND t.target_name = N'ring_buffer'),
dx
AS (SELECT dxdr.evtdata.query('.') AS deadlock_xml_deadlock_report
FROM ring_buffer
CROSS APPLY rb.nodes('/RingBufferTarget/event[@name=''database_xml_deadlock_report'']') AS dxdr(evtdata))
SELECT d.query('/event/data[@name=''deadlock_cycle_id'']/value').value('(/value)[1]', 'int') AS [deadlock_cycle_id],
d.value('(/event/@timestamp)[1]', 'DateTime2') AS [deadlock_timestamp],
d.query('/event/data[@name=''database_name'']/value').value('(/value)[1]', 'nvarchar(256)') AS [database_name],
d.query('/event/data[@name=''xml_report'']/value/deadlock') AS deadlock_xml,
LTRIM(RTRIM(REPLACE(REPLACE(d.value('.', 'nvarchar(2000)'), CHAR(10), ' '), CHAR(13), ' '))) AS query_text
FROM dx
CROSS APPLY deadlock_xml_deadlock_report.nodes('(/event/data/value/deadlock/process-list/process/inputbuf)') AS ib(d)
ORDER BY [deadlock_timestamp] DESC;
GO
DECLARE @tracename AS sysname = N'deadlocks_eventfile', @filename AS NVARCHAR (2000);
WITH eft
AS (SELECT CAST (target_data AS XML) AS rb
FROM sys.dm_xe_database_sessions AS s
INNER JOIN sys.dm_xe_database_session_targets AS t
ON CAST (t.event_session_address AS BINARY (8)) = CAST (s.address AS BINARY (8))
WHERE s.name = @tracename
AND t.target_name = N'event_file')
SELECT @filename = ft.evtdata.value('(@name)[1]', 'nvarchar(2000)')
FROM eft
CROSS APPLY rb.nodes('EventFileTarget/File') AS ft(evtdata);
IF @filename IS NULL
SELECT 'No active event file session found for: ' + @tracename AS [Error];
ELSE
BEGIN
;WITH xevents
AS (SELECT CAST (event_data AS XML) AS ed
FROM sys.fn_xe_file_target_read_file(@filename, NULL, NULL, NULL)),
dx
AS (SELECT dxdr.evtdata.query('.') AS deadlock_xml_deadlock_report
FROM xevents
CROSS APPLY ed.nodes('/event[@name=''database_xml_deadlock_report'']') AS dxdr(evtdata))
SELECT d.query('/event/data[@name=''deadlock_cycle_id'']/value').value('(/value)[1]', 'int') AS [deadlock_cycle_id],
d.value('(/event/@timestamp)[1]', 'DateTime2') AS [deadlock_timestamp],
d.query('/event/data[@name=''database_name'']/value').value('(/value)[1]', 'nvarchar(256)') AS [database_name],
d.query('/event/data[@name=''xml_report'']/value/deadlock') AS deadlock_xml,
LTRIM(RTRIM(REPLACE(REPLACE(d.value('.', 'nvarchar(2000)'), CHAR(10), ' '), CHAR(13), ' '))) AS query_text
FROM dx
CROSS APPLY deadlock_xml_deadlock_report.nodes('(/event/data/value/deadlock/process-list/process/inputbuf)') AS ib(d)
ORDER BY [deadlock_timestamp] DESC;
END
SELECT name,
is_read_committed_snapshot_on,
snapshot_isolation_state_desc
FROM sys.databases
WHERE name = DB_NAME();
-- Replace the hash value below with the query_plan_hash from the deadlock XML process node
DECLARE @query_plan_hash BINARY(8) = 0x0000000000000000;
SELECT
q.query_id,
qt.query_sql_text,
p.plan_id,
p.query_plan_hash,
TRY_CAST(p.query_plan AS XML) AS query_plan_xml,
rs.avg_duration / 1000000.0 AS avg_duration_sec,
rs.avg_logical_io_reads,
rs.count_executions
FROM sys.query_store_plan AS p
INNER JOIN sys.query_store_query AS q
ON p.query_id = q.query_id
INNER JOIN sys.query_store_query_text AS qt
ON q.query_text_id = qt.query_text_id
LEFT JOIN sys.query_store_runtime_stats AS rs
ON p.plan_id = rs.plan_id
WHERE p.query_plan_hash = @query_plan_hash
ORDER BY rs.last_execution_time DESC;
-- Replace with the schema.table from the deadlock XML resource-list
DECLARE @table_name NVARCHAR(256) = N'dbo.YourTableName';
EXECUTE sp_helpindex @table_name;
ring_buffer, or the event file query if event_file. Set @tracename to match the session name.sqlserver.database_xml_deadlock_report + ring buffer target, or enabling Azure Monitor diagnostic settings with the Deadlocks category.dl event session — Microsoft warns this can cause OOM in master and impact login processing.sqlserver.database_xml_deadlock_report (not sqlserver.xml_deadlock_report).deadlock_cycle_id — a 2-process deadlock produces 2 rows sharing the same cycle ID. Summarize each deadlock in 30 words or less.physical_database_name).query_plan_hash from the XML and use the Query Store lookup. Check indexes on involved tables with sp_helpindex.When the user asks how to prevent deadlocks, recommend in order of risk:
is_read_committed_snapshot_on = 1. Azure SQL DB enables RCSI by default; if disabled, investigate why before re-enabling.sys.event_log is NOT usable from a user database connection — it exists only in master.system_health session for deadlock file reads.ON DATABASE), not server-scoped. The DMVs are sys.dm_xe_database_sessions and sys.dm_xe_database_session_targets.Deadlocks signal.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub microsoft/microsoft-sql --plugin microsoft-sql-vscode44 skills in this plugin
/authentication-diagnosticsUse when a login fails (18456, 'Login failed for user'), a user can't open a database, a permission is denied, or an Entra or managed identity login fails. For network errors, use `connectivity-troubleshoot`./azure-functions-sql-bindingsUse when wiring Azure Functions to Azure SQL Database: a serverless CRUD API with SQL input or output bindings, SqlTrigger on row changes, a SQL trigger that never fires, an output binding that updated instead of inserting./bulk-load-and-bulk-copyUse when loading a large file or many rows into an Azure SQL Database table fast: bulk insert a CSV, bcp, SqlBulkCopy, fast_executemany, BULK INSERT or OPENROWSET refusing a local file (Msg 12713), LOG_RATE_GOVERNOR./check-live-blockingUse when queries hang right now: who is blocking, the head blocker, why a blocking DMV looks empty. Has tested queries and rules common answers miss, e.g. a sleeping head blocker is absent from sys.dm_exec_requests. For past blocking, use read-only blocking root-cause investigation using the host SQL tools./connect-from-dotnetUse when connecting a .NET app to Azure SQL Database with Microsoft.Data.SqlClient: packages, connection string, pooling, managed identity or Active Directory Default failing. For EF Core, use `ef-core-azure-sql`./connect-from-pythonUse when connecting Python to Azure SQL Database: mssql-python or pyodbc, the ODBC driver, 'data source name not found', driver missing in a container image, Entra tokens. For SQLAlchemy, use `sqlalchemy-azure-sql`.Other plugins' skills for the same job