Best practice to move SQL server table with identity insert from one server to another

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
(
[MyTableId] ASC
)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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s