且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当主键 Id 超过限制时会发生什么?

更新时间:2022-04-10 00:19:20

如果 identity 超出数据类型的界限,您的问题的其余部分将变得毫无意义,您会收到错误消息.你可以看到这个

You get an error if the identity would exceed the bounds of the datatype making the rest of your question moot. You can see this by

CREATE TABLE #T
(
id INT IDENTITY(2147483647,1)
)

INSERT INTO #T
DEFAULT VALUES

INSERT INTO #T
DEFAULT VALUES /*Arithmetic overflow error converting IDENTITY to data type int.*/

GO

SELECT * FROM #T

DROP TABLE #T