Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bulk insert in SQL Server database from one table to another

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.

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.

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

Same this in destination table

Any easy syntax will be helpful

I am using SQL Server 2008/12

like image 907
user786 Avatar asked Mar 16 '23 07:03

user786


1 Answers

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:

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.

like image 185
WaltRiceJr Avatar answered Mar 19 '23 07:03

WaltRiceJr