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?
Continue Reading This Article
Enjoy this article as well as all of our content, including E-Guides, news, tips and more.
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.
Dig Deeper on Oracle database design and architecture
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.
Meet all of our Oracle Database / Applications experts
View all Oracle Database / Applications questions and answers
Start the conversation
0 comments