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

--Use Master

--EXEC master.dbo.sp_configure 'show advanced options', 1

--EXEC master.dbo.sp_configure 'xp_cmdshell', 1

--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';

----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';



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.


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s