2

使用下面的表结构,我将如何创建一个处理 XML 数据的 bcp 批量插入。从命令行运行这一点很重要。

CREATE TABLE [dbo].[MyTable](
[Id] [uniqueidentifier] NOT NULL DEFAULT (newid()),
[MyXmlField] [xml] NULL

提前致谢...

4

2 回答 2

2

使用 bcp 的基本语法是:

bcp <table_name> <direction> <file_name> <options> 

其中参数采用以下值:

  • table_name是表的完全限定名称。例如,您可以使用inventory.dbo.fruits 将记录插入到库存数据库中由数据库所有者拥有的水果表中。
  • 方向指示您是要导入(“in”方向)还是导出(“out”方向)数据。
  • file_name是文件的完整路径。例如,您可以导入文件 C:\fruit\inventory.txt。
  • 选项允许您为批量操作指定参数。例如,您可以使用 –m 选项指定允许的最大错误数。您也可以使用 –x 选项来指定 XML 文件格式。有关完整列表,请参阅 Microsoft 的 bcp 文档。

需要更多信息才能知道要使用哪些开关,但它应该有点像

bcp database.dbo.MyTable in "C:\folder\xmlfile.xml" -c -T

-c使用字符数据类型执行操作。
-T指定 bcp 实用程序使用集成安全性通过可信连接连接到 SQL Server。

这里还有Microsoft 的 bcp Utility,它可以帮助您了解要使用的开关。

于 2010-02-15T09:19:04.343 回答
0

use -N switch if your file contains unicode characters.

-N : Performs the bulk-copy operation using the native (database) data types of the data for noncharacter data, and Unicode characters for character data. This option offers a higher performance alternative to the -w option, and is intended for transferring data from one instance of SQL Server to another using a data file. It does not prompt for each field. Use this option when you are transferring data that contains ANSI extended characters and you want to take advantage of the performance of native mode.

于 2010-02-15T12:59:34.877 回答