A deadlock in SQL Server happens when two or more sessions each hold a lock that the other session needs, and neither can proceed. SQL Server resolves this by choosing one session as the “victim” and rolling back its transaction, which means your application sees an error and the operation fails.
To diagnose deadlocks, you need the deadlock graph, an XML document that SQL Server generates for each deadlock event. The graph shows which sessions were involved, what locks they held and requested, and which objects (tables, indexes, keys) were at the center of the conflict. On-premises SQL Server captures these graphs in the system_health extended events session, while Azure SQL Managed Instance stores them in a ring buffer. Common root causes include inconsistent access order across tables, missing indexes that force broad scans, long-running transactions with wide lock footprints, and foreign key cascades.
Once you understand the pattern from the deadlock graph, fixes typically involve adding targeted indexes, reordering table access, shortening transactions, or adjusting isolation levels.
How Do You Fix SQL Server Deadlocks?
The Fix Deadlocks tuning goal helps you fix SQL Server deadlocks by extracting recent deadlock graphs and asking the AI to identify root causes and provide actionable prevention steps.
Fix Deadlocks uses the deadlock graph to identify the database objects and code paths involved. It uses that list to perform deeper follow-up analysis to review the code involved, identify the root cause, and provide specific guidance in minutes. You can also run Code Review on the stored procedures or triggers involved, or Index Tuning on the affected database to help prevent deadlocks in the future.

Table of Contents
How Does AI Analyze SQL Server Deadlock Graphs?
To fix SQL Server deadlocks effectively, the Fix Deadlocks goal follows a simple workflow:
- Collect the deadlock graph(s)
- Reads one or more recent deadlock XML graphs from the platform’s supported source.
- On-premises SQL Server: reads from the
system_healthextended events file target (sys.fn_xe_file_target_read_file). - Azure SQL Managed Instance: reads from the
system_healthring buffer (sys.dm_xe_session_targets). - If no deadlocks are found, the tool generates an informational report directly and does not call the AI.
- Collect RCSI status
- Checks
is_read_committed_snapshot_onfor the current database and includes the result in the data sent to the AI.
- Checks
- Ask the AI to review the deadlock XML
- The AI summarizes what happened in each deadlock: victim selection, each process/session, and the *resources* involved (keys/pages/objects) as described by the XML.
- Extract likely objects and code involved
- The AI attempts to identify the objects involved (tables, indexes, constraints) and—when possible—links them to likely code paths.
- If the deadlock includes an
inputbuf(statement text) for a session, the AI uses it to call out the relevant statements/procedures for follow-up. - If the XML does not include statement text or object names, the AI will still provide best-effort guidance based on lock/resource types, but object identification may be limited.
- Provide a prioritized next-step plan
- Concrete recommendations such as adding/adjusting indexes to avoid scans, enforcing consistent access order, narrowing transaction scope, or changing isolation approaches.
- A shortlist of objects to analyze next, so you can quickly focus on the most likely root cause.
Which SQL Server Platforms Support Deadlock Analysis?
Deadlock graph extraction depends on platform capabilities:
- On-premises SQL Server: Supported (reads deadlocks from
system_healthextended events file target). - Azure SQL Managed Instance: Supported (reads from
system_healthring buffer). - Azure SQL Database: Not supported (no access to
system_healthdeadlock graphs). The tool returns recommended alternatives. - Microsoft Fabric SQL Database: Not supported (treated like Azure SQL Database for deadlock extraction). The tool returns recommended alternatives.
If you run Fix Deadlocks on an unsupported platform, AI SQL Tuner Studio will return specific guidance and recommended alternatives (such as using Index Tuning, Code Review, or Azure Portal’s Query Performance Insight).
What Deadlock Data Does the Tool Analyze?
1. Recent deadlock graphs
- XML deadlock graphs with UTC timestamps
- Configurable number of recent deadlocks (1–20, default 5)
2. RCSI status
- Whether Read Committed Snapshot Isolation is enabled for the current database
- Used by the AI to inform isolation level recommendations
3. Root cause identification
When you fix SQL Server deadlocks, common root cause patterns include:
- Competing index/key order on the same tables
- Different access paths / inconsistent locking order
- Range locks (serializable / key-range)
- Foreign key cascades
- Large scans causing lock contention
4. Recommendations
To help you fix SQL Server deadlocks permanently, the AI typically provides:
- Index and query changes to enforce consistent access order
- Transaction scope reductions
- Isolation level guidance (including RCSI enablement when appropriate)
- “Retry on deadlock” guidance when appropriate
See AI SQL Tuner Studio Sample Reports for examples.
How Do You Run Deadlock Analysis?
AI SQL Tuner Studio
- Select a connection from the Connections list (or create a new one).
- Choose “Fix Deadlocks” from the tuning goal dropdown.
- Set the number of deadlocks to analyze (1–20, default 5) using the Deadlocks to analyze option.
- Database is optional — if not specified, it defaults to
master. - Optionally adjust the Reasoning effort level (Low, Medium, or High).
- Click Run.
- Progress and status are shown in the Console panel.
- When complete, the HTML report appears in the Report panel and can be saved or exported.
> Important: Fix Deadlocks is not supported on Azure SQL Database or Microsoft Fabric SQL Database. If you select one of these platforms, the tool will display recommended alternatives in the report.
For full setup instructions, see the AI SQL Tuner Studio User Guide. To create a least-privileged SQL login, see Least Privileged Account Creation.
What Results Does the Deadlock Analysis Produce?
When you use the Fix Deadlocks goal to fix SQL Server deadlocks, the AI will produce:
- Prioritized recommendations
- Specific objects involved (tables, indexes when identifiable)
- Suggested scripts where appropriate
- Prevention strategies (consistent order, targeted indexes, shorter transactions, isolation level changes)
What Format Are Deadlock Recommendations Delivered In?
Results are displayed in the Report panel as a formatted HTML report. The report footer includes the model and reasoning effort used.
Reports can be saved to HTML files using the Save Report button in the toolbar.
What If Deadlock Data Is Not Available?
“Fix Deadlocks goal is not supported on Azure SQL Database / Microsoft Fabric SQL Database”
- Expected on these platforms — the
system_healthextended events target is not accessible. - Use these alternatives:
- Index Tuning (identify missing indexes / request patterns)
- Code Review (find locking and transaction anti-patterns)
- Azure Portal’s Query Performance Insight for deadlock analysis
No deadlocks found
- When no deadlocks are found in the
system_healthsession, the tool generates an informational HTML report directly without calling the AI, saving time and cost. - The report confirms that no deadlock events were recorded and suggests running Index Tuning, Code Review, or Server Health for further analysis.
- If you expected deadlocks, verify that the
system_healthextended events session is running and that deadlocks are actually occurring on this instance.
“Access denied” / system_health not accessible
- On-premises: requires
VIEW SERVER STATEto read extended events. - Azure SQL MI: requires
VIEW SERVER STATEto read the ring buffer DMVs.
What SQL Server Permissions Are Required?
Minimum permissions needed to fix SQL Server deadlocks with the Fix Deadlocks goal:
VIEW SERVER STATE— required to readsys.fn_xe_file_target_read_file(on-premises) orsys.dm_xe_session_targets/sys.dm_xe_sessions(Azure SQL MI ring buffer)- Read access to
sys.databasesfor the RCSI status check (granted by default to public)
For detailed steps on creating a least-privileged SQL login, see Least Privileged Account Creation.
Frequently Asked Questions
What does the Fix Deadlocks tuning goal do?
Fix Deadlocks helps you fix SQL Server deadlocks by extracting recent deadlock graphs from SQL Server, sends them to an AI model for analysis, and returns a report identifying root causes, the database objects and code paths involved, and prioritized prevention steps including index changes, transaction scope reductions, and isolation level recommendations.
Which SQL Server platforms support Fix Deadlocks?
Fix Deadlocks is supported on on-premises SQL Server (reads from the system_health extended events file target) and Azure SQL Managed Instance (reads from the system_health ring buffer). It is not supported on Azure SQL Database or Microsoft Fabric SQL Database because these platforms do not expose the system_health deadlock graphs.
What happens if no deadlocks are found?
When no deadlocks are found in the system_health session, the tool generates an informational HTML report directly without calling the AI, saving time and cost. The report confirms no deadlock events were recorded and suggests running Index Tuning, Code Review, or Server Health for further analysis.
What permissions are required to run Fix Deadlocks?
Fix Deadlocks requires VIEW SERVER STATE permission to read sys.fn_xe_file_target_read_file (on-premises) or sys.dm_xe_session_targets and sys.dm_xe_sessions (Azure SQL MI ring buffer). Read access to sys.databases for the RCSI status check is granted by default to public.
What common deadlock root causes does the AI identify?
The AI identifies common patterns including competing index/key order on the same tables, different access paths with inconsistent locking order, range locks from serializable or key-range isolation, foreign key cascades, and large scans causing lock contention. It then provides targeted recommendations for each pattern found.
How many deadlocks can Fix Deadlocks analyze at once?
Fix Deadlocks can analyze between 1 and 20 recent deadlock graphs in a single run. The default is 5. You can configure this using the Deadlocks to analyze option in AI SQL Tuner Studio before clicking Run.
Related Resources
- Extended Events system_health Session (Microsoft Docs)
- Analyze and Prevent Deadlocks in Azure SQL (Microsoft Docs)
- Deadlock Analysis Example
- AI SQL Tuner Studio User Guide
- Compare AI SQL Tuner Studio Editions
AI SQL Tuner Studio Goal Comparison
| Goal | Focus | Best Used When | Requires Database? | Output |
|---|---|---|---|---|
| Index Tuning | Index and query optimization | Slow queries, missing indexes, high IO/CPU, index inefficiencies | Yes | Prioritized index and query recommendations, scripts |
| Fix Deadlocks | Deadlock analysis and prevention | Investigating deadlock graphs, blocking patterns, inconsistent access order | No (defaults to master) |
Root cause analysis, objects involved, prevention plan |
| Code Review | T-SQL best practices and anti-patterns | Reviewing stored procedures, functions, and triggers for quality and performance | Yes | Best-practice review, anti-pattern detection, rewrite suggestions |
| Server Health | Overall server health, configuration, security, and operations | Regular checkups, configuration drift, general performance issues | No (defaults to master) |
Health report, configuration guidance, security checks |