首页 > 解决方案 > 将表达式转换为数据类型 int 的算术溢出错误,即使它是 BigInt

问题描述

我试图在表中插入一行,这会引发算术溢出错误。但是,我很难理解原因!

Here's the table Columns- 
        [id] [int] IDENTITY(1,1) NOT NULL,
        [batch_number] [bigint] NOT NULL,
        [mixer_batch_history_id] [int] NULL,
        [lab_test_type_id] [int] NOT NULL,
        [lab_test_compound_id] [int] NOT NULL,
        [machine_number] [int] NULL,
        [sample_location_id] [int] NULL,
        [sample_date] [datetime] NOT NULL,
        [pass_customer_specs] [int] NOT NULL,
        [pass_internal_specs] [int] NOT NULL,
        [tested_by] [nvarchar](25) NULL,
        [last_test] [bit] NULL,
        [date_created] [datetime] NOT NULL

我正在尝试以下查询 -

DECLARE @batchNo as BIGINT = 2010000976009

INSERT INTO [LoMOS].dbo.lab_test
            (batch_number, mixer_batch_history_id, lab_test_type_id, lab_test_compound_id, machine_number, sample_location_id, sample_date, pass_customer_specs, pass_internal_specs, date_created)
     VALUES (@batchNo,  16579,  1,  128,    1,  1,  '2020-07-06 08:43:25.227',  0,  1,  '2020-07-08 07:44:27.993')
     SELECT SCOPE_IDENTITY()

哪个引发错误 -

Arithmetic overflow error converting expression to data type int.
Msg 3609, Level 16, State 1, Line 3

任何想法 ?

标签: sql-server

解决方案


根据提供的信息,错误似乎很可能来自触发器,而不是发布的插入。


推荐阅读