Tuesday, July 18, 2006

SQL SERVER : All By The Script (2) - Export Data to CSV Files

To export data to a comma separated file (csv), use the bcp command line utility:

bcp [<database-name.>][<owner.>]<table-name> in <csv-file> [/U<username>] [/P<password>] [/S<server-name>] /c /t





<database_name>

is an optional parameter specifying the name of the database.
It can only be omitted if the desired database is the default database.

<owner>
the name of the table owner.

<table_name>
the name of the table.

<csv-file>
The name of the comma separated file to generate.

<username>
The SQL Server username to use. This can be left blank if NT authentication
is used.

<password>

The password to use for the account.

<server_name>

The name of the server on which the database resides. This can be omitted
if the database is on the local machine (i.e. the same machine. as the bcp
command is issued from).

Note : (Important !!)
The flags are case sensitive.

Below are step to running this Script :
1. Clik Start
2. Click Run

3. On the Open Text box and then write : "cmd"
4. Now Command prompt will displayed
5. Write the syntax
Sample Syntax :
bcp northwind.dbo.products out products.csv /U /P /komnet /c /t


6. After the command was running, check this file ( products.csv ) on current folder.


0 Comments:

Post a Comment

<< Home