Using Delimited Identifiers with bcp

When referencing object names containing embedded special characters, such as spaces in a table name, the object name needs to be delimited with either double quotation marks (“ “) or square brackets ([ ]), and the -q parameter must be specified (when using the bcp utility). For example, to bulk copy the Order Details table in the Northwind database to the Orders.txt data file, execute at the command prompt:

bcp "Northwind..""Order Details""" out orders.txt -c -q -Sservername -Usa -Ppassword

  

OR

bcp "Northwind..[Order Details]" out orders.txt -c -q -Sservername -Usa -Ppassword

  

OR

bcp "Northwind..Order Details" out orders.txt -c -q -Sservername -Usa -Ppassword

  

Using the -q parameter causes the connection to Microsoft® SQL Server™ used by the bcp utility to have the SET QUOTED_IDENTIFIER ON statement executed. The outer quotation marks around the entire three-part object name are required because the command prompt requires any command parameter containing a blank or double quotation mark to be surrounded with double quotation marks, and any embedded double quotation mark characters (first example) to be surrounded with double quotation marks themselves.

Using the BULK INSERT statement, delimit the object name with square brackets. For example, to bulk copy the Orders.txt data file into the Order Details table in the Northwind database, execute from a query tool such as SQL Server Query Analyzer:

BULK INSERT Northwind..[Order Details] FROM 'c:\orders.txt'
WITH (

    DATAFILETYPE = 'char'

)

  

See Also
Delimited Identifiers SET QUOTED_IDENTIFIER

  


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