I am moving an Access app to SQL Server. I have confirmed the data in the existing PK is unique so I want to copy it into the new PK Identity field. The field is currently set as IDENTITY(1,1). I know I can set the IDENTITY_INSERT for the insert period, but do I then need to adjust the IDENTITY start point so the next insert does not start at 1? Example, the newest row in the existing data is id 4132, so do I insert the data then alter the column to IDENTITY (4133,1) ?
Sql-server – Existing data to new table, how to set up the PK & Identity
etlidentityprimary-keysql server
Related Question
- Sql-server – Merge Replication identity field issues
- Sql-server – How to properly increment an int identity in SQL Server if the Identity Increment isn’t set
- SQL Server Identity Property – Why Removing Identity Property on a Column is Not Supported
- SQL Server – Final Steps of Data Center Migration
- SQL Server – Generating PK Value Programmatically in Multi-Threaded Applications
- SQL Server – How to Enable Identity Insert for All Tables During Import
- SSMS Import/Export Wizard – Violation of PRIMARY KEY Constraint
Best Answer
This is simple enough to test on your own. Here's how:
Simple table:
Simple insert:
Check on the max Id and current identity value:
Both 100.
Do an out of band insert:
Check on stuff:
Both 200.
Do another insert:
Check on stuff:
Both 300.
Hope this helps!