我是否有理由实现两个函数,一个用于INT,另一个用于BIGINT?
这个问题的简单答案是不,你只需要一个函数
BIGINT
,
DECLARE @BigInt BIGINT = 922337203685477580;
DECLARE @Int INT = 2147483647;
--SET @Int = @BigInt; this wont work, so your choice is BIGINT
SET @BigInt = @Int;
这里有一个
test
具有使其非常清晰的功能。
+-----------+--------------------------------------------------------------------------+---------+
| Data type | Range | Storage |
+-----------+--------------------------------------------------------------------------+---------+
| bigint | -2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807) | 8 Bytes |
| int | -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647) | 4 Bytes |
+-----------+--------------------------------------------------------------------------+---------+
看见
int, bigint, smallint, and tinyint