MS-SQL: How do I change an existing column having an autoincrement default? I have an existing database, and a table I have a whole field is the identifier.
I would like to change this field in a field auto-incremental. I must not change the values that are already present, but I want to start counting a number greater than the highest value today.
if I'm using Sybase I can simply write
ALTER TABLE change TheTable thefield default autoincrement
But how can I do in MSSQL?
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 the 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 this. Do it on a copy of the comic first and test before hitting your DB Real.
Posted on August 3, 2010.