问题描述
使用SQLServer2019测试,执行select count(*) from lineitem; 时候会提示以下错误:
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type int.
回看lineitem表的定义,发现L_ORDERKEY这一列定义为bigint类型,因此超出了integer的范围,SQLServer在执行过程中会出现错误并报错。
在SQLServer的文档中有提到类似错误,就是值超出了integer的范围,可以参考:
解决方案:
可以使用COUNT_BIG代替count,比如:select COUNT_BIG(*) from lineitem;这样就会执行得到想要的结果,不会报错。