Our order system fails now and then with error 1205, chosen as the deadlock victim. It happens a few times a day. How do I find what is causing it?
A deadlock happens when two sessions each hold a lock the other needs. SQL Server kills one of them, which is the error you see.
Find it:
1. The system_health Extended Events session already captures deadlocks. In SSMS open Management > Extended Events > Sessions > system_health, and view the target data. Look for xml_deadlock_report events. Each shows the two queries, the tables and the locks.
2. Open the deadlock graph and note which objects and indexes are involved.
Common fixes: access tables in the same order in every procedure, keep transactions short, add the missing index so that queries lock fewer rows, and consider READ_COMMITTED_SNAPSHOT isolation. Add retry logic in the app, since a deadlock victim can safely retry the entire transaction.
Found two procedures that updated tables in opposite order. Fixed the order and the errors stopped. Thanks.