WikiGalaxy

Personalize

PostgreSQL Drop Schema

Overview:

In PostgreSQL, a schema is a namespace that contains database objects such as tables, views, and functions. The DROP SCHEMA command is used to remove an existing schema from the database.

Syntax:

The basic syntax for dropping a schema is:


DROP SCHEMA [IF EXISTS] schema_name [CASCADE | RESTRICT];
      

Parameters:

IF EXISTS: Optional clause to prevent an error if the schema does not exist.

schema_name: The name of the schema to be removed.

CASCADE: Automatically drop objects that depend on the schema.

RESTRICT: Refuse to drop the schema if it contains any objects. This is the default behavior.

Example 1: Basic Drop Schema

To drop a schema named sales:


DROP SCHEMA sales;
      

Example 2: Drop If Exists

To drop a schema named marketing only if it exists:


DROP SCHEMA IF EXISTS marketing;
      

Example 3: Drop with Cascade

To drop a schema named development and all its dependent objects:


DROP SCHEMA development CASCADE;
      

Example 4: Drop with Restrict

To drop a schema named finance only if it has no objects:


DROP SCHEMA finance RESTRICT;
      
logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025