Execute statements in batches-disable foreign keys for all tables and disable execution statements
During database migration and data import, the existence of foreign key constraints between tables causes frequent insert errors. Batch execution of SQL statements is sequential execution, I have to enter it manually.
Then, if the input is half-shining, why not disable all the foreign key constraints first?
So I am Baidu to the following materials:
Oracle Delete (all) Constraint disable (all) Constraint enable (all) Constraint (09:56:32)
Run the following SQL statement.
1
Delete all foreign key constraints
Select 'alter table' | table_name | 'drop constraint' | constraint_name | ';' from user_constraints where constraint_type = 'R'
2
Disable all foreign key constraints
Select 'alter table' | table_name | 'Disable constraint' | constraint_name | ';' from user_constraints where constraint_type = 'R'
3
Enable all foreign key constraints
Select 'alter table' | table_name | 'Enable constraint' | constraint_name | ';' from user_constraints where constraint_type = 'R'
After entering the statements in SQL Plus, many statements are generated. These statements are not actually executed. Just copy them and execute them again.
Then we can assemble the SQL statements similar to this script to obtain the required statements:
Disable all foreign key constraints:
Select 'alter TABLE "QIANHAI". "'| table_name |'" modify constraint "'| constraint_name |'" DISABLE; 'from user_constraints where constraint_type = 'R'
Enable all foreign key constraints:
Select 'alter TABLE "QIANHAI". "'| table_name |'" modify constraint "'| constraint_name |'" ENABLE; 'from user_constraints where constraint_type = 'R ';