请求select语句也会触发死锁吗

eric zhao 0 信誉分
2026-06-01T01:03:10.14+00:00

我的sqlserver版本是2016,最近遇到个死锁问题困扰了很久,三张表left join的查询触发了死锁,我印象中好像select语句是不会触发死锁的吧,请问有大神帮忙看下原因吗

用户的图像

SQL Server | 其他
0 个注释 无注释

2 个答案

排序依据: 非常有帮助
  1. 博雄 胡 765 信誉分
    2026-06-02T10:03:32.5+00:00

    默认事务隔离级别下,只要存在同时发生查询和增删改的业务场景,就可能会出现死锁。如果只有查询,就不会出现。

    所以很显然,这个查询的同时,还有增删改业务在发生。

    你可以捕捉下次发生死锁时的死锁xml,里面能告诉你哪段sql和这个查询冲突导致死锁。然后做针对性优化。

    此答案是否有帮助?


  2. Lakshmi Narayana Garikapati 1,335 信誉分 Microsoft 外部员工 审查方
    2026-06-01T16:17:03.4833333+00:00

    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.

    https://learn.microsoft.com/en-us/answers/questions/386771/deadlock-occurs-when-issuing-select-and-update-sta

    https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-deadlocks-guide?view=sql-server-ver17&

    Thanks,

    Lakshmi.

    此答案是否有帮助?


你的答案

提问者可以将答案标记为“已接受”,审查方可以将答案标记为“已推荐”,这有助于用户了解答案是否解决了提问者的问题。