Q
Problem solve Get help with specific problems with your technologies, process and projects.

How can I use INSERT INTO to copy an entire table into another?

How can I use INSERT INTO to copy an entire table into another?


 

If the tables share the same structure (same number of columns, each matching pair of columns with the same datatype), then the syntax is really simple --

insert
   into table2
 select *
   from table1

If the tables do not share the same structure, then you must name the columns of the table you are inserting into, and provide an expression for each of them in the subselect --

insert
   into table2
      ( col1
      , col2
      , col3 )
 select field3
      , ( field7 + field8 ) * 9.37
      , 0
   from table1

INSERT INTO is great because of this ability to reformat data as part of the insertion process.

 

For More Information


 

This was last published in May 2001

Dig Deeper on Oracle and SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close