Overview

The DROP SCHEMA statement deletes a specified schema along with all database objects within it. Before performing this operation, ensure you back up all critical data to prevent data loss.

Syntax

DROP SCHEMA [ IF EXISTS ] schema_name;

Parameters

  • schema_name: Specifies the name of the schema to drop.
  • IF EXISTS: An optional parameter that prevents errors if the specified schema does not exist.

Examples

  1. Drop the schema named deprecated_schema:

    DROP SCHEMA deprecated_schema;
  2. Drop the schema but suppress errors if it does not exist:

    DROP SCHEMA IF EXISTS deprecated_schema;

Notes

  • Executing DROP SCHEMA irreversibly deletes the entire schema and all objects it contains (tables, views, indexes, etc.). Before performing this operation, ensure all important data has been backed up.
  • This operation can only be executed by users with the appropriate privileges. If you lack sufficient privileges, the operation will fail with an error.

Required Privileges

The user executing DROP SCHEMA must have the DROP privilege on the corresponding schema. If you do not have the required privileges, the operation will fail with an error.