I'm performing ETL logic on a SQL Server table. I'm going to be synchronizing data from one table to another. For all of the records that need to be added to the target table based on the source table, I'm doing an insert on those rows in the target table. The schema defines one of the columns as an identity column. So SQL Server auto increments the id for new rows that are inserted. Because I'm moving existing ids, I need to remove the identity, insert those rows, then re-apply the identity, then reset the seed so it matches the source table. How can this be done programmatically?
- Can I remove the identity declaration from an existing column?
- Can I mark an existing column as an identity?
- How can I reset the seed for an identity column?