ORA-02449: Unique/primary keys in the table are referenced by foreign keys

Source: Internet
Author: User

1. Check which tables have foreign keys that reference the unique/primary keys of the tables to be deleted.

Select .*
From user_constraints A, user_constraints B
Where B. table_name = 'mytest'
And a. constraint_type = 'R'
And a. r_constraint_name = B. constraint_name;

2. generate all creation statements that reference the foreign key of the table to be deleted.

Select 'select dbms_metadata.get_ddl (''ref _ constraint '', ''' |
A. constraint_name | ''') from dual ;'
From user_constraints A, user_constraints B
Where B. table_name = 'mytest'
And a. constraint_type = 'R'
And a. r_constraint_name = B. constraint_name;

3. ExecuteSQLStatement to obtain the foreign key definition.

Sets long 3000
Set linesize 3000
Set pagesize 300
Execute the statements generated in step 2.

4. delete a table.

DropTableMytest cascade constraints;

5. Delete and recreate the table.

6. Create a foreign key constraint for the table to be created and deleted.

Execute the SQL statement obtained in step 3.

7. Check whether the foreign keys are obtained.Restore, Whether the system is normal.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.