3

我正在做一个这样的简单查询:

select * from MyTable

这会导致以下错误:

执行批处理时出错。错误信息是:算术溢出

我可以运行select top 14 * from MyTable并且它没有问题地工作,但是在第 15 个值发生错误,select top 15 * from MyTable显示算术溢出错误。

该表由具有数据类型的列组成intfloatsmallint

我已经确认错误不会发生在intorsmallint列中,因此它发生在float列中。

两个问题:

  • 由于我只选择现有值,这怎么会发生?
  • 如何查找和查看导致错误的具体值?

Microsoft SQL Server 2005 - 9.00.5057.00上运行Microsoft Windows Server 2003 R2 Standard Edition with Service Pack 2

更新设计:

USE [myDB]
GO
/****** Object:  Table [dbo].[MyTable]    Script CMte: 12/10/2019 10:35:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MyTable](
    [DeliveryYearID] [int] IDENTITY(1,1) NOT NULL,
    [DeliveryID] [int] NOT NULL,
    [DeliveryYear] [int] NOT NULL,
    [VolumeDelivery_H] [int] NOT NULL CONSTRAINT [DF__tblSaleOb__Volum__74C75C08]  DEFAULT (0),
    [VolumeDelivery_S] [int] NOT NULL CONSTRAINT [DF__tblSaleOb__Volum__75BB8041]  DEFAULT (0),
    [SurchargeSale_fast] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__Surch__76AFA47A]  DEFAULT (0),
    [SurchargeAdjust_fast] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__Surch__77A3C8B3]  DEFAULT (0.0),
    [SurchargeSale_moving] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__Surch__7897ECEC]  DEFAULT (0),
    [SurchargeAdjust_moving] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__Surch__798C1125]  DEFAULT (0.0),
    [FixedCharge_fast] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__Fixed__7A80355E]  DEFAULT (0),
    [FixedCharge_moving] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__Fixed__7B745997]  DEFAULT (0),
    [OfferedPriceP1_Edit_fast] [float] NOT NULL,
    [OfferedPriceP2_Edit_fast] [float] NOT NULL,
    [OfferedPriceP3_Edit_fast] [float] NOT NULL,
    [OfferedPriceP4_Edit_fast] [float] NOT NULL,
    [OfferedSurcharge_Edit_moving] [float] NOT NULL,
    [movingTak_moving] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__movingT__7C687DD0]  DEFAULT (0),
    [movingTakPremie_moving] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__movingT__7D5CA209]  DEFAULT (0),
    [C_VolumeDelivery] [float] NOT NULL,
    [C_ChargePerUnit] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Cha__7E50C642]  DEFAULT (0),
    [C_SurchargeBase] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Sur__7F44EA7B]  DEFAULT (0),
    [C_VolumeSurcharge_moving] [float] NOT NULL,
    [C_VolumeCost] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__00390EB4]  DEFAULT (0),
    [C_VolumeCostP1] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__012D32ED]  DEFAULT (0),
    [C_VolumeCostP2] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__02215726]  DEFAULT (0),
    [C_VolumeCostP3] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__03157B5F]  DEFAULT (0),
    [C_VolumeCostP4] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__04099F98]  DEFAULT (0),
    [C_VolumeDeliveryP1] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__04FDC3D1]  DEFAULT (0),
    [C_VolumeDeliveryP2] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__05F1E80A]  DEFAULT (0),
    [C_VolumeDeliveryP3] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__06E60C43]  DEFAULT (0),
    [C_VolumeDeliveryP4] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__07CM307C]  DEFAULT (0),
    [C_SurchargUYNrmin_fast] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Sur__08CE54B5]  DEFAULT (0),
    [C_SurchargUYNrminP1_fast] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Sur__09C278EE]  DEFAULT (0),
    [C_SurchargUYNrminP2_fast] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Sur__0AB69D27]  DEFAULT (0),
    [C_SurchargUYNrminP3_fast] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Sur__0BAAC160]  DEFAULT (0),
    [C_SurchargUYNrminP4_fast] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Sur__0C9EE599]  DEFAULT (0),
    [C_movingSurcharge_moving] [float] NOT NULL,
    [C_EffectSurcharge_moving] [float] NOT NULL,
    [C_BalanceSurcharge_moving] [float] NOT NULL,
    [C_ProfileSurcharge_moving] [float] NOT NULL,
    [C_movingKundPrisTak_moving] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Spo__0D9309D2]  DEFAULT (0),
    [C_SeparateCost_fast] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Sep__0E872E0B]  DEFAULT (0),
    [C_SeparateCost_moving] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Sep__0F7B5244]  DEFAULT (0),
    [C_VolumePrice] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__106F767D]  DEFAULT (0),
    [C_VolumePriceP1] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__11639AB6]  DEFAULT (0),
    [C_VolumePriceP2] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__1257BEEF]  DEFAULT (0),
    [C_VolumePriceP3] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__134BE328]  DEFAULT (0),
    [C_VolumePriceP4] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Vol__14400761]  DEFAULT (0),
    [C_MonthFirst] [smallint] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Mon__15342B9A]  DEFAULT (0),
    [C_MonthLast] [smallint] NOT NULL CONSTRAINT [DF__tblSaleOb__C_Mon__16284FD3]  DEFAULT (0),
    [C_SurchargeSaleAdjust_AP] [float] NOT NULL CONSTRAINT [DF_MyTable_C_SurchargeSaleAdjust_AP]  DEFAULT (0),
    [C_HourlyPercentage] [float] NOT NULL CONSTRAINT [DF_MyTable_C_HourlyPercentage]  DEFAULT (0),
    [C_OffertRisk_fast] [float] NOT NULL CONSTRAINT [DF_MyTable_C_OffertRisk_fast]  DEFAULT (0.0),
    [C_SurchargeCertificate_fast] [float] NOT NULL CONSTRAINT [DF_MyTable_C_SurchargeCertificate_fast]  DEFAULT (0.0),
    [C_TB_Sum] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_TB___23582DBF]  DEFAULT (0),
    [C_TB_PerUnit] [float] NOT NULL CONSTRAINT [DF__tblSaleOb__C_TB___244C51F8]  DEFAULT (0),
    [SurchargeMarketInvestment_fast] [float] NOT NULL DEFAULT ((0)),
    [SurchargeMarketInvestment_moving] [float] NOT NULL DEFAULT ((0)),
    [C_StructuralCostSurcharge] [float] NOT NULL DEFAULT ((0)),
    [C_FASTPRISBAS_P0] [float] NOT NULL DEFAULT ((0)),
    [C_movingPRISBAS_P0] [float] NOT NULL DEFAULT ((0)),
    [C_StructuralCostSurcharge_fast] [float] NOT NULL DEFAULT ((0)),
    [C_StructuralCostSurcharge_moving] [float] NOT NULL DEFAULT ((0)),
    [C_StructuralCostCoefficient] [float] NOT NULL DEFAULT ((0.0)),
    [C_Other_Swedish_Storage] [float] NOT NULL DEFAULT ((0.0)),
    [C_Physical_Profile_Risk] [float] NOT NULL DEFAULT ((0.0)),
    [C_Transport_Plus_Storage_Included] [float] NOT NULL DEFAULT ((0.0)),
    [C_Transport_Plus_Storage_Separate] [float] NOT NULL DEFAULT ((0.0)),
    [C_Transmission_TE_IUP_HYU] [float] NOT NULL DEFAULT ((0.0)),
    [SellerSurcharge_IUP_HYU] [float] NOT NULL DEFAULT ((0.0)),
    [AdjustedSurcharge_IUP_HYU] [float] NOT NULL DEFAULT ((0.0)),
    [C_BuyOtherPe] [float] NOT NULL DEFAULT ((0.0)),
    [BuySurcharge_HYU_in_EFR] [float] NOT NULL DEFAULT ((0.0)),
    [BuySurcharge_EFR_in_HYU] [float] NOT NULL DEFAULT ((0.0)),
    [Offered_BuySurcharge_HYU] [float] NOT NULL DEFAULT ((0.0)),
    [C_Profile_Cost_CM_EFR] [float] NOT NULL DEFAULT ((0.0)),
    [C_Volume_Risk] [float] NOT NULL DEFAULT ((0.0)),
    [C_Other_LJR_BDU] [float] NULL,
    [CorrectionValue] [float] NOT NULL DEFAULT ((0)),
    [C_UYN_Exit_Cost] [float] NOT NULL DEFAULT ((0.0)),
    [C_CapacityCost_HYU_Included] [float] NOT NULL CONSTRAINT [DF_MyTable_C_CapacityCost_HYU_Included]  DEFAULT ((0)),
    [C_CapacityCost_HYU_Separate] [float] NOT NULL CONSTRAINT [DF_MyTable_C_CapacityCost_HYU_Separate]  DEFAULT ((0)),
    [C_SurchargeP1_Etage_HYU] [float] NOT NULL CONSTRAINT [DF_MyTable_C_SurchargeP1_Etage_HYU]  DEFAULT ((0)),
    [C_SurchargeP2_Etage_HYU] [float] NOT NULL CONSTRAINT [DF_MyTable_C_SurchargeP2_Etage_HYU]  DEFAULT ((0)),
    [C_SurchargeP3_Etage_HYU] [float] NOT NULL CONSTRAINT [DF_MyTable_C_SurchargeP3_Etage_HYU]  DEFAULT ((0)),
    [C_SurchargeP4_Etage_HYU] [float] NOT NULL CONSTRAINT [DF_MyTable_C_SurchargeP4_Etage_HYU]  DEFAULT ((0)),
    [C_SurchargeP1_Etage_EFR] [float] NOT NULL CONSTRAINT [DF_MyTable_C_SurchargeP1_Etage_HYU1]  DEFAULT ((0)),
    [C_SurchargeP2_Etage_EFR] [float] NOT NULL CONSTRAINT [DF_MyTable_C_SurchargeP2_Etage_HYU1]  DEFAULT ((0)),
    [C_SurchargeP3_Etage_EFR] [float] NOT NULL CONSTRAINT [DF_MyTable_C_SurchargeP3_Etage_HYU1]  DEFAULT ((0)),
    [C_SurchargeP4_Etage_EFR] [float] NOT NULL CONSTRAINT [DF_MyTable_C_SurchargeP4_Etage_HYU1]  DEFAULT ((0)),
    [C_Surcharge_Etage_HYU] [float] NOT NULL CONSTRAINT [DF_MyTable_C_Surcharge_Etage_HYU]  DEFAULT ((0)),
    [C_Surcharge_Etage_EFR] [float] NOT NULL CONSTRAINT [DF_MyTable_C_Surcharge_Etage_EFR]  DEFAULT ((0)),
 CONSTRAINT [MyTable2_PK] PRIMARY KEY NONCLUSTERED 
(
    [DeliveryYearID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[MyTable]  WITH CHECK ADD  CONSTRAINT [MyTable3_MyTable_FK1] FOREIGN KEY([DeliveryID])
REFERENCES [dbo].[MyTable3] ([DeliveryID])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[MyTable] CHECK CONSTRAINT [MyTable3_MyTable_FK1]

更新 2:

找到导致错误的列:[C_SurchargUYNrminP2_fast]

select top 15 [C_SurchargUYNrminP2_fast] from MyTable

更新 3:

测试了@LukStorms 建议的查询。收到错误:

消息 9100,级别 23,状态 2,行 2 检测到可能的索引损坏。运行 DBCC CHECKDB。

-- Change col1 to your actual primary key column(s), col2 to the column from the 2570 error, table1 to the table from the CHECKDB output
SELECT col1, col2 FROM table1
WHERE col2<>0.0 AND (col2 < 2.23E-308 OR col2 > 1.79E+308) AND (col2 < -1.79E+308 OR col2 > -2.23E-308)

https://support.microsoft.com/en-us/help/923247/troubleshooting-dbcc-error-2570-in-sql-server-2005-and-later-versions

更新 4:

命令:DBCC CHECKTABLE(N'dbo.MyTable') WITH DATA_PURITY

消息 2570,级别 16,状态 3,第 1 行页面 (1:30707),对象 ID 1330364054 中的插槽 8,索引 ID 1,分区 ID 72057615345844224,分配单元 ID 72057615349710848(类型“行内数据”)。列“C_SurchargUYNrminP2_fast”的值超出了数据类型“float”的范围。将列更新为合法值。

4

1 回答 1

4

感谢@DanGuzman 和评论中的其他人。

使用以下命令找到损坏的值:

DBCC CHECKTABLE(N'dbo.MyTable') WITH DATA_PURITY

消息 2570,级别 16,状态 3,第 1 行页面 (1:30707),对象 ID 1330364054 中的插槽 8,索引 ID 1,分区 ID 72057615345844224,分配单元 ID 72057615349710848(类型“行内数据”)。列“C_SurchargUYNrminP2_fast”的值超出了数据类型“float”的范围。将列更新为合法值。

然后我可以DBCC PAGE用来查找损坏的值和相应的主键。有了这个帮助,我可以更新值。

https://blogs.msdn.microsoft.com/sqlserverstorageengine/2006/06/10/how-to-use-dbcc-page/

DBCC TRACEON ( 3604 )
DBCC PAGE ( 'myDB' , 1 , 30707 , 3 )
DBCC TRACEOFF ( 3604 )

插槽 8 列 1 偏移量 0x4 长度 4

交货 ID = 123

插槽 8 列 33 偏移量 0xf0 长度 8

C_SurchargUYNrminP2_fast = -1.#IND

于 2019-12-10T11:49:18.507 回答