看板 Database 關於我們 聯絡資訊
(針對 SQL 語言的問題,用這個標題。請用 Ctrl+Y 砍掉這行) 資料庫名稱: SQL Server 資料庫版本:Microsoft SQL Server 2012 - 11.0.5343.0 內容/問題描述: 我的程式會依序執行以下SQL --判斷指定AID的ItemID是否為空 select * from testdb where AID = @AID and PokeDate = @date and isnull(ItemID, 0)>0 --如果資料不存在就存檔 BEGIN IF NOT EXISTS (SELECT * FROM testdb WHERE AID = @AID and PokeDate = @date) BEGIN Insert into (Acc,AID,CreateTime,UserIP,PokeDate) values(@Acc,@AID,@CreateTime,@UserIP,@PokeDate) END END --Update剛才Insert進來的資料 update testdb set ItemID = @ItemID, ItemCount = @ItemCount, ItemName = @ItemName, RewardQueueID = @RewardQueueID where Acc = @Acc and PokeDate = CONVERT(char(10), @PokeDate ,126) 死結會發生在update的query 完整錯誤訊息 Transaction (Process ID 74) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction. 我試過在select加上with(nolock)也沒用 這情形之前沒發生過 懷疑是Insert那段的IF判斷導致的 我直接在DB嘗試觸發死結 設了延遲但都正常 不太清楚是哪段SQL導致資源被lock住 想問這種情形該怎麼debug呢 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.218.40.109 ※ 文章網址: https://www.ptt.cc/bbs/Database/M.1504776511.A.6A4.html
elfishhare: 會不會是 insert 未 commit 又被 update 的關係? 10/20 00:46
jackiechin: 是insert的原因 11/16 19:14