Pages

Delete data from tables

Ever needed to clear all the data from your database (usually while in development)?
You can use this script to clean the tables. It will work for oracle only, AFAIK.

-- script to clean the tables (ie the deleting the data only)
DECLARE
cursor c1 is select distinct table_name from user_tab_columns;

BEGIN
for v1 in c1 loop
dbms_output.put_line('cleaning '|| v1.table_name ||'...');
execute immediate 'Delete from '|| v1.table_name ||'';
dbms_output.put_line('done');
end loop;
dbms_output.put_line('completed');
END;

Disclaimer: I hold no responsibility for the havoc this script may create on your database ;) never use it on production databases.

No comments: