827
Chapter 31: Managing Data in Windows Azure SQL Database
31
The bcp utility is fl exible and powerful, and you can apply a lot of options to it. This section doesn’t go into the entire
range of bcp options or dive deep into the many uses of the utility. You can fi nd that information in the SQL Server
Books Online or on the Microsoft MSDN web site at http://msdn.microsoft.com/en-us/library/
ms162802.aspx.
This section describes how to use the bcp utility to export data from a local database and
import the data into your Azure SQL Database. It also discusses some things you should
watch out for when using the bcp utility for SQL Database.
Invoking BCP
The bcp utility has no GUI; it’s a command prompt–driven utility. But don’t let that
intimidate you, especially given what you’re using it for. It’s fl exible and can seem a bit
overwhelming, but it’s quite simple. The basic syntax for the bcp utility is as follows:
bcp table direction filename -servername -username -password
where:
■ (^) table is the source or destination table based on the direction parameter.
■ direction is in or out, depending on whether you copy data into the database or
out of the database.
■ filename is the fi lename you copy data to or from.
■ (^) servername is the name of the server you copy data to or from.
■ username is the username used to connect to either the local or SQL Azure data-
base instance.
■ password is the password associated with the username.
Now start by exporting the data from your source database.
Exporting the Data
Begin by copying data out of your local SQL instance. Open a command prompt, and type
the command, as shown in Figure 31-19. Enter your own values for the server name, the
target directory, and the username and password for your local server. (The password is
blanked out in Figure 31-19.)
In this example you use the out keyword for the direction parameter. That’s because you
copy data out of SQL Server.
The -n parameter performs the bulk-copy operation using the native database data types
of the data. The -q parameter executes the set quoted_identifiers on statement in
the connection between the bcp utility and your SQL Server instance.
c31.indd 827c31.indd 827 7/31/2012 10:00:30 AM7/31/2012 10:00:30 AM
http://www.it-ebooks.info