Dropping all tables in database
Just for development purposes
-- Database clearing script
-- This PL/SQL procedure drops all tables which names
-- are present inUSER_TABLES
set serveroutput on;
DECLARE
CURSOR c_get_tables IS
SELECT table_name from user_tables;
BEGIN
FOR cursor_item IN c_get_tables
LOOP
EXECUTE IMMEDIATE
'DROP TABLE ' || cursor_item.table_name || ' CASCADE CONSTRAINTS';
dbms_output.put_line('Dropped table: ' || cursor_item.table_name);
-- There's no DML operations so transaction commit is not needed.
END LOOP;
END;
Written by Kamil Michalak
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Sql
Authors
Related Tags
#sql
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#