Bajwa Consulting Need senior Oracle DBA help? Performance tuning, Cloud migrations, GoldenGate, backup and DR. Plus 70+ free DBA scripts.
Visit bajwaconsulting.com →

Friday, April 25, 2014

How to drop columns from a very large table

Let's say you have a very large table called MOVIES with this type of data


  1* select  movie_name,genre , comments from movies where rownum < 10
SQL> /

MOVIE_NAME                GENRE                COMMENTS
------------------------- -------------------- ---------------
The good The Bad The Ugly Western              asdf
Titanic                   Drama                asdf
Avatar                    Science Fiction      asdf
Gravity                   Science Fiction      asdf
Groundhog Day             Comedy               asdf
junk                      as                   asdf
The good The Bad The Ugly Western              asdf
Titanic                   Drama                asdf
Avatar                    Science Fiction      asdf

9 rows selected.

 



Now you want to drop the column called "Comments". This is a two step operation

1. Set the column to be unused.

SQL> alter table movies set unused (comments)
  2  /

Table altered.

Elapsed: 00:00:00.24


2. Drop the column with this command.

SQL> alter table movies drop unused columns
  2  /

Table altered.

Elapsed: 00:00:38.77
SQL>

1 comment: