Re: Drop a table with foreign key constraints

  • From: Gus Spier <gus.spier@xxxxxxxxx>
  • To: orasnita@xxxxxxxxx
  • Date: Fri, 30 Jul 2010 12:35:04 -0400

Among all the other excellent responses you will see here, also consider
investigating the supplied procedure, DBMS_METADATA.

With this tool, you extract the DDL from the database for your constraints
and other dependant objects.  You can find the documentation at
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_metada.htm#i1015856
in brief, use:

select DBMS_METADATA.GET_DEPENDENT_DDL(
   object_type => 'TABLE',
   base_object_name => <target table name>,
   base_object_schema => <schema name>)
from DUAL
/

gl

Gus


2010/7/30 Octavian Rasnita <orasnita@xxxxxxxxx>

>  Hello,
>
> I want to make some changes in a table, like changing the order and type of
> its columns, adding some new columns after or before some specified columns
> and so on, but I understood that this is not possible in Oracle without
> re-creating the table.
>
> Because of this, I want to drop the current table and create a new one, but
> many other tables have foreign keys that depend on this table, so it can't
> be dropped easy.
>
> I know that I could just use
> drop table table_name cascade constraints;
> but this would drop all the constraints from those many tables and it would
> be hard to re-create them again (and I might miss some of them).
>
> Is there a way of disabling all the constraints regarding the table that
> should be deleted, drop the table and then enable the constraints again in
> an easy way?
>
> Thanks.
>
> --
> Octavian
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 5324 (20100729) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>

Other related posts: