How to take backup of table in sql server using CMD/BCP

Backup sql table using BCP (BULK COPY PROGRAM)

The bcp utility is a command-line utility in SQL Server that allows for the customization of importing and exporting data from text files and SQL Server tables.

Export:

Use below command to export data.you can use any extension *.dat or *.txt
bcp DBA.dbo.EMP_DETAILS out C:\Users\Documents\DBA.dbo.EMP_DETAILS.dat -n -T

Note:- 
  1.  You must have bulk import / export privileges or SYSADMIN access.
  2. -n denotes native SQL data types, which is key during restore
  3. -T denotes that you are connecting to SQL Server using Windows Authentication, in  case you want to connect using SQL Server Authentication use -U<username> -P<password>
 OUTPUT:-



File Location:- C:\Users\Documents\



Import:

To perform import you need have to create same table structure to destination.

Step 1:  Right click on table --> Properties-->Script Table as-->Create To-->New Query Window


Output : Table structure




Step 3: Execute table script to destination. Change the table name if required.


Step 4: Now restore table backup which we have taken on path C:\Users\Documents\
             *.dat file



            *.txt file

Final Output of export & Import

Thats all :)

More:




No comments:

Post a Comment