我认为也在这里,您只能插入一整行或什么都不插入。
如果您的客户表如下所示:
customer
custid|co_name |addr |phone |remarks
42|Laverda |Breganze, Italy |+39 6 233 84 81 |(NULL)
43|Benelli |Pesaro, Italy |+39 8 284 55 32 |(NULL)
44|Ural |Irbit, Russia |+7 14 526 22 2342|(NULL)
45|Dnepr |Kiew, Ukraine |+380 526 22 2342 |(NULL)
46|Harley Davidson|Milwaukee, US |+1 802 223 4444 |(NULL)
47|Honda |Tokyo, Japan |+81 82 555 4123 |(NULL)
48|Moto Guzzi |Mandello del Lario, Italy|+39 6 423 04 72 |(NULL)
49|Ducati |Bologna, Italy |+39 7 722 04 43 |(NULL)
50|Norton |Birmingham, UK |+44 7234 723 4423|(NULL)
51|Matchless |Plumstead, London, UK |+44 8021 612 0843|(NULL)
52|Brough |Nottingham, UK |+44 5812 512 4883|(NULL)
(好吧,您使用ALTER TABLE 添加remarks 列...),那么,我希望您提到的带有备注的文件看起来有点像这样:
remarks
custid|remarks
42|built also tractors, closed now
43|first series 6-cylinder motorbike
44|old style sidecar rigs with modern engine
45|old style sidecar rigs, permanent two-wheel drive
46|the american classic
47|builders of the CB 750 four and the gold wing
48|famous for horizontal singles and 90° V twins
49|90° V twin bikes with lateral crankshaft
50|english classic, still alive
51|english classic, closed now
52|probably the finest motorcycles ever built
因此,您将构建一个remarks_stg 表:
CREATE TABLE remarks_stg (
custid SMALLINT NOT NULL
, remarks VARCHAR(50) NOT NULL
);
然后,您只需使用上述数据文件加载该暂存表 - 并且,至少如果有 SQL Server 2008 及更高版本,则使用MERGE 语句更新customer 表:
MERGE customer t
USING stg_customer s
ON t.custid = s. custid
WHEN MATCHED THEN UPDATE SET
remarks = s.remarks
;