1. 程式人生 > >訊息 8134,級別 16,狀態 1,第 1 行 遇到以零作除數錯誤

訊息 8134,級別 16,狀態 1,第 1 行 遇到以零作除數錯誤

  這兩天遇到一個非常奇怪的問題,給人的感覺有點匪夷所思,如下所示,在更新一個表的統計資訊時,會遇到“遇到以零作除數錯誤”,本來這個錯誤是屬於數學錯誤,但是居然出現在更新統計資訊的SQL語句裡面

UPDATE STATISTICS [dbo].[FIInspectFabric] SAMPLE 20 PERCENT;

訊息 8134,級別 16,狀態 1,第 1 行

遇到以零作除數錯誤。

UPDATE STATISTICS [dbo].[FIInspectFabric] WITH FULLSCAN;

訊息 8134,級別 16,狀態 1,第 1 行

遇到以零作除數錯誤。

clipboard

如果我更新統計資訊的SQL語句不帶引數,則會執行成功。如下所示

UPDATE STATISTICS [dbo].[FIInspectFabric];

DBCC CHECKTABLE('FIInspectFabric')也沒有發現任何問題,Google、Bing搜尋了很久也沒有查到相關資料。

image

問題出在哪裡?一直沒有答案。直到我檢查這個表的索引時,發現在表FIInspectFabric的欄位A、B上建立了主鍵索引、然後不知道那個程式設計師又在欄位A上建立了兩個索引(嚴重鄙視之),於是刪除了這兩個索引後,重新執行上面語句OK,問題消失了,於是我建立了測試表,想重現這個錯誤,很奇怪,怎麼也重現不了這個錯誤。

====***************************************************2015-07-21日補充

************************************************====

今天又出現了這個錯誤,重建索引後,問題依然存在,在檢查這個表的統計資訊時,發現除了索引對應的統計資訊外,還有大量額外的統計資訊,於是我將這些統計資訊全部刪除(系統會根據需要自動建立)。然後去跟新統計資訊,問題解決。

DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000006_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000007_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000008_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000009_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000000A_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000000B_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000000C_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000000D_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000000E_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000000F_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000010_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000011_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000012_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000013_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000014_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000015_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000016_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000017_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000018_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000019_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000001B_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000001D_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000001E_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000001F_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000020_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000021_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000022_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000023_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000024_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000025_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000026_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000027_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000028_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000029_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000002A_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000002B_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000002C_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000002D_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000002E_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000002F_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000030_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000031_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000032_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000033_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000034_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000035_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000036_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000003C_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000003F_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000040_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000041_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000042_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000043_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000044_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000045_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000046_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000047_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000048_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_00000049_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000004C_712A3EA0
DROP STATISTICS FIINSPECTFABRIC._WA_Sys_0000004E_712A3EA0

====***************************************************2017-06-09日補充************************************************====

今天同事反饋在SELECT這個表的時候也遇到了這個錯誤,我立馬想到了可能是有計算列的問題,檢查了一下表結構,發現有一個欄位確實是用其它列計算,終於解開了這個案例的謎底! 只是在這種機緣巧合的情況下,總有點怪怪的感覺,試想,如果當時檢查一下表結構,也許就能解開真相了!

[HundredYard_Points] AS (case when [Quantity]=(0) then (0) else floor(((isnull([Total_Def_Point_SendedYorn],[Total_Def_Point])*(3600))/(isnull([Width],(1))*(isnull([Quantity],(1))-isnull([Allow_Quantity],(0)))))*(100))/(100) end)