<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/sql-server-deadlock-slow-cooked-a-recipe-for-two-sessions-qsmvz1nfn" -->

---
title: SQL Server Deadlock, Slow-Cooked: A Recipe for Two Sessions
description: Two sessions update two tables in opposite order and reliably deadlock on SQL Server 2025. Session A updates Pantry then Fridge with a 5-second wait between;...
canonical: https://daily.dev/posts/sql-server-deadlock-slow-cooked-a-recipe-for-two-sessions-qsmvz1nfn
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: SQL Server Deadlock, Slow-Cooked: A Recipe for Two Sessions | daily.dev
og:description: Two sessions update two tables in opposite order and reliably deadlock on SQL Server 2025. Session A updates Pantry then Fridge with a 5-second wait between;...
og:url: https://daily.dev/posts/sql-server-deadlock-slow-cooked-a-recipe-for-two-sessions-qsmvz1nfn
og:image: https://api.daily.dev/og/posts/qsmVz1nFN.png
og:image:alt: SQL Server Deadlock, Slow-Cooked: A Recipe for Two Sessions
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL Server Deadlock, Slow-Cooked: A Recipe for Two Sessions

**[SQL Authority](https://daily.dev/sources/sql-authority)** · 5 min read · 0 upvotes · 0 comments

## Summary

Two sessions update two tables in opposite order and reliably deadlock on SQL Server 2025. Session A updates Pantry then Fridge with a 5-second wait between; Session B updates Fridge then Pantry a second later. Session B gets error 1205 and is rolled back, while Session A commits after waiting 3.4 seconds. The fix: always touch tables in the same order across code paths, keep transactions short, and retry on error 1205 since the other side has usually finished by then.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.sqlauthority.com/2026/10/28/slow-cooked-deadlock>

## Questions this post answers

### What causes a deadlock in SQL Server when two sessions update the same two tables?

A deadlock happens when two sessions access two tables in opposite order inside transactions left open too long. One session updates table A then waits before updating table B, while the other updates B then waits before updating A; each ends up holding a lock the other needs. SQL Server picks one transaction as the 'deadlock victim', rolling it back with error 1205 so the other can finish.

_Debugging a SQL Server deadlock right now? Track detailed root-cause write-ups like this one on daily.dev._

### How do I fix or prevent error 1205 deadlock victim in SQL Server?

Make every code path access tables in the same order so a circular wait can't form, since that fix costs nothing. Keep transactions short by never holding one open across a network call or user prompt, and retry once on error 1205, since the message explicitly says 'Rerun the transaction' and the competing transaction has usually finished by then.

_Developers hardening transaction logic against deadlocks can keep fixes like this close on daily.dev._

### How can I see why SQL Server chose a particular deadlock victim?

SQL Server records every deadlock in the system_health extended events session, which can be read back from the event file to show the processes, the lock resources each was waiting for, and which one was chosen as the victim. The deadlock graph lists the key locks involved (for example two KEY locks on separate tables) but does not explain the victim-selection reasoning itself.

_Teams chasing recurring deadlocks can keep diagnostic walkthroughs handy on daily.dev._

## Similar posts on daily.dev

- [SQL Server Deadlock: Build One With Your Own Hands](https://daily.dev/posts/sql-server-deadlock-build-one-with-your-own-hands-mpg3offv0) · SQL Authority · 0 upvotes · 0 comments
- [The lock that killed my migration](https://daily.dev/posts/the-lock-that-killed-my-migration-rpiz4vna3) · The Art of Simplicity · 1 upvotes · 0 comments
- [How to Fix Postgres ERROR: deadlock detected](https://daily.dev/posts/how-to-fix-postgres-error-deadlock-detected-s28daquxh) · Medium · 0 upvotes · 0 comments
- [Database troubleshooting for Umami](https://daily.dev/posts/database-troubleshooting-for-umami-narits9sg) · Chen Hui Jing · 3 upvotes · 0 comments
- [Deadlock or Just a Queue? Find the Wait Cycle](https://daily.dev/posts/deadlock-or-just-a-queue-find-the-wait-cycle-b66co4aem) · SQL Authority · 0 upvotes · 0 comments

---

Tags: [#database](https://daily.dev/tags/database), [#microsoft-sql-server](https://daily.dev/tags/microsoft-sql-server)

[View this post on daily.dev](https://daily.dev/posts/sql-server-deadlock-slow-cooked-a-recipe-for-two-sessions-qsmvz1nfn)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"SQL Server Deadlock, Slow-Cooked: A Recipe for Two Sessions","url":"https://daily.dev/posts/sql-server-deadlock-slow-cooked-a-recipe-for-two-sessions-qsmvz1nfn","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/sql-server-deadlock-slow-cooked-a-recipe-for-two-sessions-qsmvz1nfn"},"datePublished":"2026-10-28T05:09:56.410Z","dateModified":"2026-10-28T05:45:24.331Z","description":"Two sessions update two tables in opposite order and reliably deadlock on SQL Server 2025. Session A updates Pantry then Fridge with a 5-second wait between;...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/8077820743309d4d59223e3f8c537ad9?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/8077820743309d4d59223e3f8c537ad9?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"SQL Authority","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"SQL Authority","logo":"https://media.daily.dev/image/upload/s--reCGnvgi--/f_auto,q_auto/v1780213436/logos/sql-authority?_a=BAMAMiWQ0","url":"https://daily.dev/sources/sql-authority"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/sql-server-deadlock-slow-cooked-a-recipe-for-two-sessions-qsmvz1nfn","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"database,microsoft-sql-server","timeRequired":"PT5M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"SQL Authority","item":"https://daily.dev/sources/sql-authority"},{"@type":"ListItem","position":3,"name":"SQL Server Deadlock, Slow-Cooked: A Recipe for Two Sessions"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/sql-server-deadlock-slow-cooked-a-recipe-for-two-sessions-qsmvz1nfn#faq","mainEntity":[{"@type":"Question","name":"What causes a deadlock in SQL Server when two sessions update the same two tables?","acceptedAnswer":{"@type":"Answer","text":"A deadlock happens when two sessions access two tables in opposite order inside transactions left open too long. One session updates table A then waits before updating table B, while the other updates B then waits before updating A; each ends up holding a lock the other needs. SQL Server picks one transaction as the 'deadlock victim', rolling it back with error 1205 so the other can finish. Debugging a SQL Server deadlock right now? Track detailed root-cause write-ups like this one on daily.dev."}},{"@type":"Question","name":"How do I fix or prevent error 1205 deadlock victim in SQL Server?","acceptedAnswer":{"@type":"Answer","text":"Make every code path access tables in the same order so a circular wait can't form, since that fix costs nothing. Keep transactions short by never holding one open across a network call or user prompt, and retry once on error 1205, since the message explicitly says 'Rerun the transaction' and the competing transaction has usually finished by then. Developers hardening transaction logic against deadlocks can keep fixes like this close on daily.dev."}},{"@type":"Question","name":"How can I see why SQL Server chose a particular deadlock victim?","acceptedAnswer":{"@type":"Answer","text":"SQL Server records every deadlock in the system_health extended events session, which can be read back from the event file to show the processes, the lock resources each was waiting for, and which one was chosen as the victim. The deadlock graph lists the key locks involved (for example two KEY locks on separate tables) but does not explain the victim-selection reasoning itself. Teams chasing recurring deadlocks can keep diagnostic walkthroughs handy on daily.dev."}}]}
```

