批量插入固定宽度字段 [英] Bulk insert fixed width fields
本文介绍了批量插入固定宽度字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用批量插入命令指定字段长度?
How do you specify field lengths with the Bulk Insert command?
示例:如果我有一个名为 c:\Temp\TableA.txt 的表并且它有:
Example: If I had a table named c:\Temp\TableA.txt and it had:
123ABC
456DEF
我有一张桌子,例如:
use tempdb
CREATE TABLE TABLEA(
Field1 char(3),
Field2 char(3)
)
BULK INSERT TableA FROM 'C:\Temp\TableA.txt'
SELECT * FROM TableA
那么如何指定 Field1 和 Field2 的长度?
Then how would I specify the lengths for Field1 and Field2?
推荐答案
我觉得你需要定义一个格式文件
I think you need to define a format file
例如
BULK INSERT TableA FROM 'C:\Temp\TableA.txt'
WITH FORMATFILE = 'C:\Temp\Format.xml'
SELECT * FROM TableA
不过,要实现这一点,显然您需要一个格式文件.
For that to work, though, you need a Format File, obviously.
有关创建一个的一般信息,请参见此处:
See here for general info about creating one:
猜测,通过查看架构,这样的事情可能会做到:
At a guess, from looking at the Schema, something like this might do it:
<?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="CharFixed" LENGTH="3"/>
<FIELD ID="2" xsi:type="CharFixed" LENGTH="3"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="Field1" xsi:type="SQLCHAR" LENGTH="3"/>
<COLUMN SOURCE="2" NAME="Field2" xsi:type="SQLCHAR" LENGTH="3"/>
</ROW>
</BCPFORMAT>
这篇关于批量插入固定宽度字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文