BCP: export data to azure database
BCP (bulk copy program) is a great way to transfer huge data (millions of rows) to an Azure database. I found that it is very efficient in terms of ease of use and speedy with which the data could be transferred. The bcp utility is a command line utility that ships with Microsoft SQL Server. It bulk copies data between SQL Azure (or SQL Server) and a data file in a user-specified format. The bcp utility that ships with SQL Server 2008 R2 is fully supported by SQL Azure.
Following are the steps to use this utility to export the data to a flat file and then exporting the data to the Azure database:
- Copy data from customer table into a temp table
- select * into [temp_employee] from employee
- Copy data to local file from a table in a local database.
- BCP [server_name].[database_name].[schema_name].[temp_employee] OUT c:\temp\employee.txt -T –c
- Create the temp table in the destination database in the cloud
- Copy data into the azure database.
- BCP [azure_database_name].[schema_name].[employee] IN c:\temp\employee.txt -S servername.database.windows.net; -U <username>@<servername> -P <password>
Following is a sample of the Bulk copy output form the command window for reference. The most interesting aspect to observer is that data transfer rate stood at 5206 rows per second for this particular attempt. I believe that higher transfers could be a possibility depending on the available network bandwidth.
Exporting Data out of SQL Azure
Data can be retrieved in a a huge set from the in SQL Azure by running the following statement at the Windows command prompt:
bcp [database_name].[schema_name].[table_name] out C:\temp\[file_name].txt -c -U username@servername -S tcp:servername.database.windows.net -P password
References:
Leave a Reply