【1】報錯信息
【1.1】運行增刪查改時報錯
我這里是運行刪除操作的時候報的錯
操作的刪除語句:
IF OBJECT_ID('tempdb..#temp_Robot') IS NOT NULL DROP TABLE #temp_Robot CREATE TABLE #temp_Robot(UserID INT NOT NULL PRIMARY KEY) select * from #temp_robot INSERT INTO #temp_Robot SELECT UserID FROM Db_Tank..Sys_Users_Order WHERE IsRobot IN (1,3) DELETE FROM #temp_Robot WHERE UserID IN (SELECT UserID FROM Db_Tank..Sys_Users_Detail WHERE ConsortiaID>0)
--核心語句在這里 DELETE Db_Tank..Sys_Users_History WHERE UserID IN (SELECT UserID FROM #temp_Robot)
報錯信息:
Location: lckmgr.cpp:9421 Expression: NULL == m_lockList.Head () SPID: 56 Process ID: 5972 Location: "xact.cpp":2630 Expression: !m_updNestedXactCnt SPID: 56 Process ID: 5972 Description: Trying to use the transaction while there are 1 parallel nested xacts outstanding Location: "xact.cpp":2788 Expression: !m_updNestedXactCnt SPID: 56 Process ID: 5972 Description: Trying to use the transaction while there are 1 parallel nested xacts outstanding Location: "xact.cpp":3851 Expression: !m_parNestedXactCnt SPID: 56 Process ID: 5972 Description: Trying to use the transaction while there are 7 parallel nested xacts outstanding Location: "xact.cpp":2879 Expression: !m_updNestedXactCnt SPID: 56 Process ID: 5972 Description: Trying to use the transaction while there are 1 parallel nested xacts outstanding 消息 3624,級別 20,狀態 1,第 1 行 系統斷定檢查已失敗。有關詳細信息,請查看 SQL Server 錯誤日志 消息 0,級別 20,狀態 0,第 0 行 當前命令發生了嚴重錯誤。應放棄任何可能產生的結果。
系統日志報錯:
【1.2】運行還原時報錯
90%是備份文件出了問題,另外可能是原主數據庫本身就有問題,那備份文件自然就有問題了。
具體參考我另一篇文章:
https://www.cnblogs.com/gered/p/12174111.html
【2】排查辦法
一般情況下,這種都是SQL中使用的條件中的相關列所在的索引出了問題
(1)使用select count(1) from Db_Tank..Sys_Users_History
發現也是卡頓,連查詢都不能查,明顯有問題啊。count(1) 探索的是聚集索引列
(2)查看表結構 sp_help Sys_Users_History
只有一個userid的聚集索引,正好我們刪除也是用它來關聯的。估計問題就出在這里了。
當然,這只是經驗之談,如果沒什么經驗的朋友建議運行DBCC CHECKDB('db_name') 檢查一下這個庫。
【3】解決辦法,重建索引
use db_tank go alter index PK_Sys_Users_History on Sys_Users_History rebuild
OK,搞定!
【4】總結
出了問題不要慌,要想辦法定位原因,然后得以解決