Exporting data into a text or csv file and Importing the same data into another table from text file with Bulk Copy Processing(BCP)

The below BCP command will export the data(OUT) from table to a text file(.txt) and from the .txt file it will import(IN) the data to another table. Commands are give below.

BCP AdventureWorks2014.Person.Person out D:\Test_Person_Peron.txt -S RAMESH\PROD -T -c -b10 -t

-S  --> ServerName

-T  --> Windows Authentication

-b10 --> The amount of batches

-t    --> Delimiter values(Eg:',', SPACE, TAB)

-c    --> If you pass this this will not ask for "Enter the file storage type of field <field_name> [<default>]:"




Running BCP command with SQL Query here is the command





The below command will BCP out to a CSV(excel file). If you see excel it will capture all column information in single column. However it will appropriately insert the data into destination table.






The below BCP command will push the data into required table from .CSV file . Here is the command.



Comments

Popular posts from this blog

System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

Pre login Handshake or Connection Timeout Period

Transparent Data Encryption(TDE) with Master Key and Certificate in SQL Server