What happens to the primary key Id when it goes over the limit?

前端 未结 3 1834
失恋的感觉
失恋的感觉 2020-11-30 15:15

If you add a new record, then delete the record, then add it again over and over, in time, sooner or later, when you add a new record the integer primary key id, it will eve

相关标签:
3条回答
  • 2020-11-30 15:24

    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
    
    0 讨论(0)
  • 2020-11-30 15:41

    This is a comment I found on a similar question and I will leave it here for future users who might be worried about overflow of a BIGINT.

    If you use a BIGINT IDENTITY starting at 1, and you insert one thousand rows every second, you need a mind-boggling 292 million years before you hit the 922 quadrillion limit

    0 讨论(0)
  • 2020-11-30 15:45

    Use BIGINT and you likely will never reach the limit.

    0 讨论(0)
提交回复
热议问题