Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Int Primary key - exceeding int range

Just wondering what actually happens after you exceed 2147483647 records?

like image 781
001 Avatar asked Dec 07 '10 18:12

001


2 Answers

try it out

CREATE TABLE #tester (
    testerid INT IDENTITY(1, 1) not null CONSTRAINT pk_tester 
    PRIMARY KEY CLUSTERED)

DBCC checkident(#tester, reseed, 2147483647)

INSERT #tester DEFAULT VALUES 
INSERT #tester DEFAULT VALUES 

Msg 8115, Level 16, State 1, Line 1
Arithmetic overflow error converting IDENTITY to data type int.

See also What To Do When Your Identity Column Maxes Out for a quick fix

like image 107
SQLMenace Avatar answered Sep 21 '22 03:09

SQLMenace


Most people forget there is a negative side to int which is one bigger than the positive side. If you think you might outrun the positive int values just start your identity at the negative end of the range -2,147,483,648. Or to really play with new DBA start at 2,147,483,647 and step by -1.

like image 28
RC_Cleland Avatar answered Sep 19 '22 03:09

RC_Cleland