I have a table with an Id field type int in SQL Server. 10 years later, can save more if Id reached the maximum value is 2,147,483,647? How to resolve if the table can not be saved anymore?
2 Answers
You could always modify the column type. Note that you can't do this while the column is part of the primary key, so you'd have to drop the constraint and then re-create it:
ALTER TABLE mytable DROP CONSTRAINT mytable_pk;
ALTER TABLE mytable ALTER COLUMN id BIGINT NOT NULL;
ALTER TABLE mytable ADD CONSTRAINT mytable_pk PRIMARY KEY (id);
Comments
You can alter the table and change the column data type to bigint anytime, but it is much recommended to have a trigger which will notify the DBA. Just in case if it's a primary key column, you have to delete the constraint, alter the column, change the data type and then add the primary key constraint again. Same would be the case if the column is a foreign key to some other table.
-2147483648, giving you double the numbers you had before. if you've already initialised theIDENTITYthis doesn't help, but it's worth keeping in mind.