ORA-02449 Oracle Drop Table Error

Sometimes when dropping a table in Oracle database by executing DROP TABLE SQL statement, Oracle may return the error ORA-02449 as below:

ORA-02449: unique/primary keys in table referenced by foreign keys

The Oracle error is caused by the attempt to drop a table with unique or primary keys referenced by foreign keys in another table, or in other word, the table that is referenced as a parent table by a foreign key constraint in a parent-child relationship that established between two tables through a foreign key. Oracle does not allow to drop tables referenced by foreign keys of other tables without specifying the CASCADE CONSTRAINTS option in the DROP TABLE statement, or to drop the parent table without first removing the foreign key.

The solution and workaround for the error when you want to drop tables referenced by child tables, is to use the CASCADE CONSTRAINTS option in the DROP TABLE statement. For example:

DROP TABLE table_name CASCADE CONSTRAINTS;

The CASCADE CONSTRAINTS option in the DROP TABLE SQL statement will drop the FOREIGN KEY constraints of the child tables referenced.

Alternatively, you can manually drop and remove the foreign key key constraints in other tables before performing the DROP TABLE operations on the parent table, drop the foreign key constraints in other tables. To check what constraints are referencing a table in Oracle, use the following command:

SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME = “table_name“;

To drop and delete the user constraints in Oracle use the following command in SQL*Plus, Toad or other SQL tools:

ALTER TABLE table_name DROP CONSTRAINT constraint_name;


4 Responses to “ORA-02449 Oracle Drop Table Error”

  1. Michael Komisarenko
    April 7th, 2009 18:56
    4

    If you need to recreate a table you do not have to drop constraints. As an alternative you can disable constraints and then enable them back again.
    The correct select statement to see which foreign keys reference the primary key of the parent table is as follows:

    SELECT TABLE_NAME, CONSTRAINT_NAME
    FROM USER_CONSTRAINTS
    WHERE CONSTRAINT_TYPE = ‘R’
    AND R_CONSTRAINT_NAME = parent_table_primary_key;

    You can use EXECUTE IMMEDIATE to disable constraints without necessarily dropping them.

  2. sangam
    July 24th, 2008 13:21
    3

    Great! The information provided is very helpful. It seems to be simple but really halps an lot. Thanks again.

  3. f
    July 3rd, 2008 06:30
    2

    Constrangimentos? Orra, meu revisa essa tradução aí e testa antes de postar!!! Se não seja honesto e indica o link de onde pegou!!!

  4. vipin
    February 8th, 2007 18:51
    1

    what if after dropping the table using the query blow you want again all those constraints.

    DROP TABLE table_name CASCADE CONSTRAINTS;

    please tell the query if u knows.

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. To receive notification of latest comments posted, subscribe to My Digital Life Comments RSS feed or register to receive new comments in daily email digest.
Custom Search

New Articles

Incoming Search Terms for the Article

ora-02449 - ORA-02449: unique/primary keys in table referenced by foreign keys - ora-02449 drop table - oracle force drop table - drop table force oracle - drop table ORA-02449 - drop table force - force drop table - oracle drop table cascade - oracle drop table force - dropping oracle table when there is foreign key issue - force drop table oracle - drop table oracle - oracle drop error - drop table oracle force - ora drop table return code - oracle drop with cascade option - ora 02449 disable - oracle drop table ora-02449 - partially dropped table oracle - remove unique drop key - drop table with primary key in oracle; - force drop table + oracle - ORA-02449: - Oracle how to remove foreign key constraints for all tables for a user - oracle dynamically drop constraint - oracle cascade constraints - oracle "drop constraint" - cascade option in oracle - check dropped tables oracle - drop table table_name cascade constraints; - izvorni ora - ora-02449 dropping interim table - oracle sql 'DROP TABLE CASCADE CONSTRAINTS' - ora-02449 unique primary keys in table referenced by foreign keys - oracle drop table having foreign key - oracle drop all constraints user - primary keys in table referenced by foreign keys; - HARD DROP TABLE ORACLE - oracle ORA-02449 - drop table referenced by foreign key in oracle - ORA 02449 - oracle force table drop - error ora-20000 "unique" - ORA -00604:+not able to drop the table - oracle drop table does not exist - oracle drop constraint ORA-00942 - TOAD CREATE CONSTRAINT ON TOAD - unique/primary keys in table referenced by foreign keys - drop table Student cascade constraints; -