未归入特定类别的其他 SQL Server 功能和主题
默认事务隔离级别下,只要存在同时发生查询和增删改的业务场景,就可能会出现死锁。如果只有查询,就不会出现。
所以很显然,这个查询的同时,还有增删改业务在发生。
你可以捕捉下次发生死锁时的死锁xml,里面能告诉你哪段sql和这个查询冲突导致死锁。然后做针对性优化。
我的sqlserver版本是2016,最近遇到个死锁问题困扰了很久,三张表left join的查询触发了死锁,我印象中好像select语句是不会触发死锁的吧,请问有大神帮忙看下原因吗
未归入特定类别的其他 SQL Server 功能和主题
Hi @eric zhao ,
Thanks for reaching out to SQL Q&A Forum
Even though SELECT queries don’t modify data, they can still participate in deadlocks in SQL Server. This happens because SELECT acquires shared locks under the default isolation level, which may conflict with exclusive locks from concurrent UPDATE or INSERT operations. When multiple transactions hold locks that the other needs, SQL Server detects a cycle and chooses one query as the deadlock victim — often the SELECT. To reduce these conflicts, you can consider options like adding appropriate indexes, using snapshot isolation (row versioning), or reviewing query design to ensure consistent access order across tables. Capturing a deadlock graph will help identify the exact queries and resources involved.
Thanks,
Lakshmi.