Oracle - Drop Table
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;
page revision: 2, last edited: 29 Mar 2019 18:58