-2

I have a table with millions of rows. I need to insert data from this table into another table in the same database.

How do I insert the data from one table to another table in bulk using sql query in SQL Server 2012.

jarlh
  • 42,561
  • 8
  • 45
  • 63
prashanth
  • 7
  • 3
  • `INSERT INTO SELECT`. Good luck. – Radu Gheorghiu Oct 05 '15 at 10:22
  • 2
    This is *extremely* easy to Google. Even googling `How do I insert the data from one table to another table in bulk using sql query in SQL Server 2012.` leads to a result. – Pekka Oct 05 '15 at 10:23
  • Do you want all rows, or just a few of them? If millions of rows, I'd consider copying it in parts, to keep transaction size reasonably small. – jarlh Oct 05 '15 at 10:24

2 Answers2

0
SELECT * INTO NewTableName FROM OldTableName

Try this.

Pedram
  • 6,256
  • 10
  • 65
  • 87
  • If the table he wants to insert into already exists, then this will fail. This will work only when the destination table does not exist. – Radu Gheorghiu Oct 05 '15 at 10:24
  • yeah I understand. but I have provided the solution for new table. he should be able to understand this thing. – Pedram Oct 05 '15 at 10:26
0

you can create and populate a table in sql server very easy like this :

select *
into   NewTable
from   yourtable

and when you want to copy into an existing table you can use this

insert into existingtable (field1, field2,...)
select field1, field2,... from yourtable
GuidoG
  • 11,359
  • 6
  • 44
  • 79