为什么在将bigint数字插入bigint列时出现算术溢出错误?

问题描述 投票:0回答:2

我正在尝试在列中插入数字。列数据类型是BIGINT,我很确定我的数字不超过BIGINT的最大值,但我仍然得到

Msg 8115, Level 16, State 2, Line 40
Arithmetic overflow error converting expression to data type int.
The statement has been terminated.

我最近的活动是将该列的数据类型从INT更改为BIGINT。我认为我的内部某处仍然定义为INT。

这是我的剧本。

Insert into Customer(Cust_ID)
Select 2150000000

列Cust_ID数据类型在设计器中是BIGINT。它也是PRIMARY_KEY和许多表引用它。

编辑:这是一些迁移脚本

DROP TABLE dbo.Customer
GO
EXECUTE sp_rename N'dbo.Tmp_Customer', N'Customer', 'OBJECT' 
GO
sql sql-server sql-server-2014 sqldatatypes
2个回答
0
投票

您收到错误不是因为尝试将2150000000插入Customer.Cust_ID

如果您尝试在bigint列中插入一个非常大的数字,则错误消息将如下所示:

Arithmetic overflow error converting expression to data type bigint.
The statement has been terminated.

您的错误消息提及data type int,而不是bigint

您没有显示完整的脚本。问题出在第40行。


0
投票

好的,我已经找到了答案。我的表有自定义约束,它调用需要INT参数的标量函数。

将所有这些函数的参数更改为BIGINT可以解决问题。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.