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.