MSSQLMSSQL 1205

MSSQL 1205: Transaction Was Deadlocked

SQL Server error 1205 is raised when SQL Server detects a deadlock between two or more transactions and automatically terminates the one with the lowest deadlock priority as the deadlock victim.

Example Query

-- Session 1: UPDATE orders SET status='X' WHERE id=1
-- Session 2: UPDATE orders SET status='Y' WHERE id=2
-- Session 1: UPDATE orders SET status='X' WHERE id=2 -- blocked
-- Session 2: UPDATE orders SET status='Y' WHERE id=1 -- deadlock!

Common Causes

  1. 1Two transactions updating the same rows in reverse order
  2. 2Long-running transactions holding locks while doing application-level work
  3. 3Missing indexes causing table scans that lock too many rows

How to Fix It

Access resources in a consistent order across all transactions. Keep transactions short. Add retry logic in the application for error 1205. Enable trace flag 1222 or use the system_health Extended Events session to capture deadlock graphs.

Need a reliable database?

Try Supabase — free PostgreSQL with a generous free tier. No credit card required.

Get started free →

Got a query causing this error?

Paste it into SQLbuddy and get an instant plain-English explanation with optimization tips.

Analyze My Query →