Sql-server – SQL Record Transfer from one db to another instance having same table structure

sql serversql-server-2012

I want to move data from server db table to local db table but need to make sure that the Ids of records won't change while copying from main Server db table.
like enter image description here

The issue I am having is when I move this to local, it merges the next to last record of the table and starts incrementing from number 20.
I want the Ids to remain concurrent or the same in both Local and Production Db.
Any possible Solutions?

Best Answer

You can use SET IDENTITY_INSERT my_table ON before performing the insertion of the data in you local table and on finish use SET IDENTITY_INSERT my_table OFF and your column will take the following value.

Example:

SET IDENTITY_INSERT [dbo].[table] ON

GO

INSERT INTO [dbo].[table] ([CustomerID] ,[FirstName]) VALUES (1 ,'qqq');

INSERT INTO [dbo].[table] ([CustomerID] ,[FirstName]) VALUES (2 ,'eee');

SET IDENTITY_INSERT [dbo].[table] OFF