cancel
Showing results for 
Search instead for 
Did you mean: 

Copy records from one table to another

Former Member
0 Kudos

Hi

   I want to copy data from one table to another. Fields in both the tables are same. Do i need to loop through each record or with 1 sql statement data can be copied like in SQL . For e.g Insert into test select * from temp

Thanks

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member241304
Active Participant
0 Kudos

Hi Sonu,

Im providing the Example go through it :-

INSERT INTO #TempTable (ID, Date, Name)
SELECT id, date, name
FROM physical_table



Here  #TempTable is the temporary table And Don't forget to drop the temporary table after you have finished with it and before you try creating it again.

AdKerremans
Active Contributor
0 Kudos

Hi Sonu,

It can work, but i suggest you specifiy the fields, just in case the sequence of the fields are different in both tables

Regards

Ad

Former Member
0 Kudos

Hi Kerremans

   Can u please help me in detail how it can be done. Both the tables have same fields & no of fields is also same

Thanks

AdKerremans
Active Contributor
0 Kudos

Hi Sonu,

Like this:

insert into test (field1, field2, field3)

select field1, field2, field3 from temp

Regards

Ad

former_member183373
Active Participant
0 Kudos

Hi Sonu,

you can also try this;

SELECT * INTO Table_2 FROM TABLE_1

Regards,

Atilla

edy_simon
Active Contributor
0 Kudos

Hi Atilla,

Select Into statement will copy current record into a NEW table.

It will throw an error if your Table_2 already exists.

I believe the OP needs to copy to an existing identical copy of a table.

Regards

Edy

former_member183373
Active Participant
0 Kudos

Hi Edy,

I missed that part. You are right about it.

Regards,

Atilla