Re: dropping table column

From: Dale Cooper <cooper_at_seismo.CSS.GOV>
Date: 5 Oct 1993 12:10:07 GMT
Message-ID: <28ro6v$1j6_at_seismo.CSS.GOV>


In article <28r4lk$28e_at_plootu.Helsinki.FI> heinamak_at_plootu.Helsinki.FI (Olli Heinamaki) writes:
>In <8044.2cb05683_at_hayes.com> fgreene_at_hayes.com writes:

->correct.  The only way to do it is to drop the entire t able and then recreate
->it using the correct column definitions.  If you have to retain the data
->you must make sure to save it as well.

>Another way to do this is to create a temporary table with the columns
>that are needed. E.g. if you have: Table_1 (Col_1, Col_2, Col_3, Col_4)
>and you want to drop column Col_3, create table Table_2 :
 

> SQL> create table Table_2 as select Col_1, Col_2, Col_4 from Table_1;
 

>The columns in Table_2 will be named the same as in Table_1. Drop table
>Table_1 and create NEW Table_1 :
 

> SQL> drop table Table_1
> SQL> create table Table_1 as select * from Table_2;
> SQL> drop table Table_2;
 

>Now you have Table_1 with the columns you wanted.

Why not just rename Table_2 to Table_1 after Table_1 is dropped?

Works just fine...

	SQL> create table Table_2 as select Col_1, Col_2, Col_4 from Table_1;
	SQL> drop table Table_1;
	SQL> rename Table_2 to Table_1;

That way you don't need to create yet another table...

Dale Cooper, DBA
Center for Seismic Studies
Arlington, VA

>Olli Heinamaki, Computing Center, University of Helsinki, Finland
>Mail : Olli.Heinamaki_at_Helsinki.FI Tel.: + 358-0-708-4645 (work)
> heinamaki_at_finuh.bitnet + 358-0-345-3580 (home)
Received on Tue Oct 05 1993 - 13:10:07 CET

Original text of this message