BCP — Another Script with -b -S and Identity Column


 
--Use Master
--GO

--EXEC master.dbo.sp_configure 'show advanced options', 1
--RECONFIGURE WITH OVERRIDE
--GO

--EXEC master.dbo.sp_configure 'xp_cmdshell', 1
--RECONFIGURE WITH OVERRIDE
--GO
 

--Table A1
----bcp out with Identity column
exec master..xp_cmdshell  'bcp [myDB].[dbo].[A1] OUT "C:\temp\myA1.txt" -T -c -b 10000 -S MyMachine\myInstance';

 go
----bcp in with all data
exec master..xp_cmdshell  'bcp [myDB].[dbo].[A1_bcp] IN "C:\temp\myA1.txt" -T -c -b 10000 -S MyMachine\myInstance';

go 

 

When you use bcp to move data from a table with identity column, you can generate the script from source table for your target table. The identity value may change from your original values if you have gaps in your source. If you want to keep all values same, you need to turn off the identity feature in your target table.

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