Delete the data from All tables in Oracle

In this case I need to delete all the Data in my tables because I'm making test of upload all the Data, and I'm too lazy to delete all the tables and create them again, so I'll show you a way to delete all the data :).

First you need to disable all the constraints, or at least foreign keys, if you don't do it, you can get an error unless you delete the tables in the right order. watch this post to disable them.

Disable and Enable All table constraints in Oracle

Now that you have disabled all the constraints, run the next pl/sql block that will delete all the data in all the tables. and as you don't have constraints, you will not get errors :D.
begin
for r in (select table_name from user_tables) LOOP
 execute immediate('delete '||r.table_name);
END LOOP;
end;
After do it, active again the constraints and it is done, you have deleted all the data from the tables, now you can celebrate that you have a clean data Base ready to test or first use :D. Now you can continue with your work and it will be great if you do it listening the below song ;).


Comments

Popular posts from this blog

View PDF File on APEX (Simple approach)

Set Custom APP Icon on APEX

ID Basado en trigger y secuencia para todas las tablas - Oracle