Saturday, December 1, 2012

Cloning a DB table and renaming

create table PIPPO as (select * from PLUTO where 1 = 2);

this will create an empty table.

Unfortunately, neither PK nor FKs nor indexes will be created.

The not null constraints WILL be created.

rename PIPPO to PLUTO;

will change the table name. Be careful because all the old indexes associated to PIPPO will now be associated to PLUTO, so you might have to rename also indexes.

No comments: