SQL Server查詢未提交事務,終止進程,解除表鎖,sqlserver進程死結

來源:互聯網
上載者:User

SQL Server查詢未提交事務,終止進程,解除表鎖,sqlserver進程死結

如果數據庫中有未提交的事務,相關表將一直處於死鎖狀態,從而影響其他進程的查詢(除非在查詢中用with (nolock))。
由於事務的隔離性,其他Session無法簡單通過RollBack Transaction來回滾事務,只能終止未提交事務所在會話的進程,然後由於事務的原子性,終止其進程,事務也就回滾了。

如何找出未提交的事務呢?
運行如下命令:

DBCC OpenTran

結果如下:

SPID即進程ID,再運行如下命令,終止進程即可:

kill 52 -- 52就是未提交事務會話所在SPID

另附相關其它查詢:

 -- 查詢鎖定的表select      object_name(P.object_id) as TableName,        resource_type, resource_description,request_session_id,L.resource_database_idfrom    sys.dm_tran_locks L    join sys.partitions P on L.resource_associated_entity_id = p.hobt_idWHERE L.resource_database_id = DB_ID();--查詢阻塞(Blocked)進程SELECT * FROM sys.dm_exec_requests WHERE blocking_session_id<>0

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.