SQL DROP SCHEMA Tutorial

Table of contents

DROP SCHEMA

  • Works in PostgreSQL, MySQL, and SQL Server.
  • Throws an error if the schema isn’t empty.
DROP SCHEMA schema_name;

DROP SCHEMA IF EXISTS

  • Works in PostgreSQL, MySQL, and SQL Server.
  • Only attempts to drop the schema if it exists.
  • Useful for cleaning up logs by avoiding unnecessary errors.
DROP SCHEMA IF EXISTS schema_name;

DROP SCHEMA CASCADE

DROP SCHEMA schema_name CASCADE;

Oracle DROP SCHEMA

DROP USER user_name; -- Drops user if their schema is empty DROP USER user_name CASCADE; -- Drops user and all tables in their schema