Oracle - Drop Table

oracle

How can we drop a table if it exists?

BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE TABLE_NAME';
EXCEPTION
    WHEN OTHERS THEN NULL;
END;
/

How can we drop a table?

DROP TABLE tableName;
DROP TABLE schemaName.tableName;

How can we drop a table and all of its constraints?

DROP TABLE tableName CASCADE CONSTRAINTS;

How can we drop all tables?

select 'drop table '||table_name||' cascade constraints;' from user_tables;

Review the result. Copy and paste the result into another window and execute.

select 'Drop ' || object_type || ' ' || object_name || ';' from user_objects
where object_type in ('TABLE','VIEW')
ORDER BY object_type DESC, object_name;
select 'drop '||object_type||' '|| object_name||  DECODE(OBJECT_TYPE,'TABLE',' CASCADE CONSTRAINTS;','')from user_objects;
purge recyclebin;
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License