Link to home
Start Free TrialLog in
Avatar of Joalkat
Joalkat

asked on

Oracle Insert from One Table to Another Table, Same Schema

I want to copy rows from one TableA, with over a million records,  to anther TableB with identical column names, both in the same Schema.  TableB is completely emply, but has several more columns, so in effect, TableA is a subset of TableB.  How do I copy rows from Table A to the empty, Table B?  Thanks.
Avatar of ajexpert
ajexpert
Flag of United States of America image

There you go
INSERT INTO TABLEB (col1,col2,col3) SELECT * FROM TABLEA

Open in new window

Avatar of Joalkat
Joalkat

ASKER

Great!  Answered my question.
ASKER CERTIFIED SOLUTION
Avatar of ajexpert
ajexpert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mark Geerlings
If performance is an issue, you may want to do a couple more things.

First: "alter tableb nologging"
Second: repeat that command for each index on tableb, for example: "alter index tableb_ix1 nologging"
Third: do the insert like this:
insert /*+APPEND */ into tableb (col1,col2,col3) SELECT * FROM TABLEA;

This may allow the insert to be *MUCH* faster.  You should do a backup though of the tablespace for tableb and for any indexes on tableb after the load, since the load will not be recoverable otherwise.
Avatar of Joalkat

ASKER

I'll shoot you the 50 points once I understand how to release.  Thanks for your patience.