我正在使用这样的命令:
bcp "tablename" format nul -w -x -f "Format.xml" -d databasename -S servername -G
正在生成格式文件(经删节),如下所示:
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="1" xsi:type="NCharTerm" TERMINATOR="\t\0" MAX_LENGTH="42"/>
<FIELD ID="2" xsi:type="NCharTerm" TERMINATOR="\t\0" MAX_LENGTH="32" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="3" xsi:type="NCharTerm" TERMINATOR="\t\0" MAX_LENGTH="256" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<!-- ABRIDGED -->
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="ID" xsi:type="SQLBIGINT"/>
<COLUMN SOURCE="2" NAME="BUSINESS_UNIT" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="3" NAME="SERVICE_NUMBER" xsi:type="SQLVARYCHAR" />
<!-- ABRIDGED -->
</ROW>
</BCPFORMAT>
但是,SQL Server中SERVICE_NUMBER的数据类型可以为空,因此,我希望这样:
<COLUMN SOURCE="3" NAME="SERVICE_NUMBER" xsi:type="SQLVARYCHAR" NULLABLE="YES"/>
-k命令似乎仅用于导入,而我希望格式文件作为记录已导出数据文件表示的已知模式的一种方式存在。
答案 0 :(得分:1)
Yes, -k is for the "in" operation of BCP. You cannot get the information you are seeking from a format file.
As for getting document to "show the known schema" why not just query the INFORMATION_SCHEMA views and bcp out their contents?
bcp "select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = '' order by ORDINAL_POSITION" queryout .... (the rest of our BCP command)