Q

Alternate way to alter table

I created a table with 10 columns and have about 100,000 records in it. I want to alter the structure of the table. Currently Oracle has the alter table add columns option and it works fine. I want to do this in a different way. I want to export the table's data, delete the data in the existing table, alter the table and then import it. Can I do this in Oracle 10g?

I created a table with 10 columns and have about 100,000 records in it. I want to alter the structure of the table. Currently Oracle has the alter table add columns option and it works fine. I want to do this in a different way. I want to export the table's data, delete the data in the existing table, alter the table and then import it. Can I do this in Oracle 10g? If so, how?
To me, the best way to add a column is to do the following:
ALTER TABLE table_name ADD (column_name datatype);
I'm not sure why you do not want to use the above command as it works great! However, you have another option at your disposal with slightly more work. This option involves copying the data to another table, re-creating the original table and moving the data back:
CREATE TABLE my_table_interim AS SELECT * FROM my_table;
DROP TABLE my_table;
CREATE TABE my_table ( ....);
INSERT INTO my_table (col1, col2 ...) 
  SELECT col1, col2, ... FROM my_table_interim;
DROP TABLE my_table_interim;
In the INSERT statement above, you will have to explictily denote which columns you are copying from the interim table to the destination table since both tables will have a different number of columns.
This was last published in September 2006

Dig Deeper on Oracle database design and architecture

PRO+

Content

Find more PRO+ content and other member only offers, here.

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.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close