从一个表到另一个表中大量插入SQL Server数据库。

时间:2022-04-14 09:37:52

I have 200k records in one table and I want to insert these records into another table. I read about the bulk insert but the query I found on msdn website is just not making any sense.

我在一个表中有200k的记录,我想把这些记录插入到另一个表中。我读了关于批量插入的内容,但是我在msdn网站上找到的查询没有任何意义。

This is the query

这是查询

 BULK INSERT AdventureWorks2012.Sales.SalesOrderDetail
 FROM 'f:\orders\lineitem.tbl'
 WITH 
  (
     FIELDTERMINATOR =' |',
     ROWTERMINATOR =' |\n'
  );

What is f:\orders\lineitem.tbl and the whole this is just not making any sense.

什么是f:\ \ lineitem的订单。tbl和整个这是没有任何意义的。

I have a table with four columns: id, frm, to1 and country

我有一张四栏的表格:id、frm、to1和country

Same this in destination table

在目标表中也一样

Any easy syntax will be helpful

任何简单的语法都是有帮助的。

I am using SQL Server 2008/12

我正在使用SQL Server 2008/12

1 个解决方案

#1


4  

BULK INSERT imports from an external data file. If you already have the data in a SQL Server table, then you should do something like:

批量插入从外部数据文件导入。如果您已经拥有SQL Server表中的数据,那么您应该执行以下操作:

INSERT INTO NewTable (field1, field2, field3)
SELECT field1, field2, field3 FROM OldTable

DO NOT point BULK INSERT at your SQL Server database file. The .tbl file referenced in your example code is to a text file with delimited fields.

不要将批量插入指向SQL Server数据库文件。在您的示例代码中引用的.tbl文件是一个带分隔字段的文本文件。

#1


4  

BULK INSERT imports from an external data file. If you already have the data in a SQL Server table, then you should do something like:

批量插入从外部数据文件导入。如果您已经拥有SQL Server表中的数据,那么您应该执行以下操作:

INSERT INTO NewTable (field1, field2, field3)
SELECT field1, field2, field3 FROM OldTable

DO NOT point BULK INSERT at your SQL Server database file. The .tbl file referenced in your example code is to a text file with delimited fields.

不要将批量插入指向SQL Server数据库文件。在您的示例代码中引用的.tbl文件是一个带分隔字段的文本文件。