Posted on January 5, 2012.
MS-SQL: How do I change an existing column having an autoincrement defaulta I have an existing database, and in a table that I have a whole field is the identifier.
I would like to change this field in a field auto-incremental. I must not change values that are already present, but I want to start counting a number greater than the highest value now.
if I'm using Sybase I can simply write
Alter table modify TheTable thefield default autoincrement
But how can I do in MSSQLa
You can not in MSSQL.
You must either create a new table, copy data, delete the old table and rename the new.
Or create a new column, copy data, delete the existing column and rename the new.
More difficult if you have constraints on the table / column.
Make sure you know what you are doing before trying it. Do it on a copy of the db first and test before hitting your real db.