Oracle SQL

How to delete all table except database ?

How to delete all table except database
Written by shohal

How to delete all table except database :

Step 1:

Print the deleted all table for below query:

DECLARE sql_query VARCHAR2(100);
BEGIN
FOR table_rec IN (SELECT table_name
FROM all_tables
WHERE owner = 'Your_Selected_Schema') LOOP
sql_query := 'DROP TABLE ' || table_rec.table_name || ' CASCADE CONSTRAINTS';
DBMS_OUTPUT.PUT_LINE(sql_query);
END LOOP;
END;

Note: Your_Selected_Schema Must be Capital.

Step 2:

Execute the deleted all table for below query:

DECLARE sql_query VARCHAR2(100);
BEGIN
FOR table_rec IN (SELECT table_name
FROM all_tables
WHERE owner = 'Your_Selected_Schema') LOOP
sql_query := 'DROP TABLE ' || table_rec.table_name || ' CASCADE CONSTRAINTS';
EXECUTE IMMEDIATE sql_query;
END LOOP;
END;

🚀

If you’d like me to proceed with any of these, please just let me know from the site techtweet.xyz! Also if you need to learn something new than subscribe YouTube : ASP.NET With SQL SERVER

About the author

shohal

I have profession and personal attachment with custom ERP Software development, Business Analysis, Project Management and Implementation almost (36) ,also Oracle Apex is my all-time favorite platform to developed the software. Moreover i have some website development experience with WordPress. For hand on networking experience DevOps and CCNA, it create me a full package. Here are some core programming language with networking course i have been worked: Oracle SQL ,PL/SQL,Oracle 19c Database , Oracle Apex 20.1,WordPress,Asp.Net ,MS SQL ,CCNA ,Dev Ops, SAP SD

Leave a Comment