Today we wanted to move a table with identity insert from one server (development) to other (production) along with data.
1)Use script to create the new table with Identity
CREATE TABLE [dbo].[MyTable]
[MyTableId] [int] IDENTITY(1,1) NOT NULL,
[Field1] [int] NULL,
[Field2] [nvarchar] (50) NULL,
[Field3] [nvarchar] (max) NULL,
CONSTRAINT [tblMyTable$PrimaryKey] PRIMARY KEY CLUSTERED
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
2)Now use the import export wizard to upload the data, with “Enable identity Insert” checked.