Running the bcp Utility

The data file containing the imported data needs to be in row/column format so that the bcp utility can understand how the data is to be inserted. Microsoft® SQL Server™ can accept data in any ASCII or binary format as long as the terminators (characters used to separate columns and rows) can be described. The structure of the data file need not be identical to the structure of the SQL Server table because bcp allows columns to be skipped or reordered during the bulk copy process.

Data bulk copied into SQL Server is appended to any existing contents of a table; data bulk copied from SQL Server to a data file overwrites the previous contents of the data file.

The prerequisites for bulk copying data are:

Importing and Exporting Data Example

To bulk copy data from the publishers table in the pubs database to the Publishers.txt data file in ASCII text format, execute from the command prompt:

bcp pubs..publishers out publishers.txt -c -Sservername -Usa -Ppassword

  

The contents of the Publishers.txt file:

0736 New Moon Books Boston MA USA
0877 Binnet & Hardley Washington DC USA
1389 Algodata Infosystems Berkeley CA USA
1622 Five Lakes Publishing Chicago IL USA
1756 Ramona Publishers Dallas TX USA
9901 GGG&G München   Germany
9952 Scootney Books New York NY USA
9999 Lucerne Publishing Paris   France

Conversely, to bulk copy data from the Publishers.txt file into the publishers2 table in the pubs database, execute from the command prompt:

bcp pubs..publishers2 in publishers.txt -c -Sservername -Usa -Ppassword

  

Alternatively, using the BULK INSERT statement from a query tool such as SQL Server Query Analyzer to bulk copy data:

BULK INSERT pubs..publishers2 FROM 'c:\publishers.txt'
WITH (DATAFILETYPE = 'char')

  


Note The publishers2 table needs to be created first.


See Also
bcp Utility Managing Security Accounts
Native Format bcp ImportData Method
BULK INSERT ExportData Method
Character Format bcp  

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.