I'm pretty new to SQL, so it sould be rather easy to answer my questions.
Here is what I want to do:
Deactivate constraints:
Deactivate constraints in the database:
begin for cur in (select fk.owner, fk.constraint_name , fk.table_name from all_constraints fk, all_constraints pk where fk.CONSTRAINT_TYPE = 'R' and pk.owner = 'USER1' and fk.R_CONSTRAINT_NAME = pk.CONSTRAINT_NAME ) loop execute immediate 'ALTER TABLE '||cur.owner||'.'||cur.table_name||' MODIFY CONSTRAINT '||cur.constraint_name||' DISABLE'; end loop; end;Delete from tables:
delete from USER_TEST.Table1; delete from USER_TEST.Table2; delete from USER_TEST.Table3;Reactivate Constraints:
begin for cur in (select fk.owner, fk.constraint_name , fk.table_name from all_constraints fk, all_constraints pk where fk.CONSTRAINT_TYPE = 'R' and pk.owner = 'USER1' and fk.R_CONSTRAINT_NAME = pk.CONSTRAINT_NAME ) loop execute immediate 'ALTER TABLE '||cur.owner||'.'||cur.table_name||' MODIFY CONSTRAINT '||cur.constraint_name||' ENABLE NOVALIDATE'; end loop; end;
Does anyone know how to combine these steps into one .sql script so I can run this on Oracle SQLDeveloper? Or maybe a more elegant way to perform the deletion from the tables?
I'd be very thankful
DELETEDELETEtransaction.