Skip to content
Related Articles

Related Articles

Improve Article
PostgreSQL – ALTER SCHEMA
  • Last Updated : 28 Aug, 2020

PostgreSQL has A ALTER SCHEMA statement that is used to modify the definition of an existing schema.

Syntax:
ALTER SCHEMA schema_name
ACTION xyz;

Let’s analyze the above syntax:

  • First, specify the name of the schema that you want to modify after the ALTER SCHEMA keywords.
  • Second, specify the operation you need to perform.
  • ACTION can be any valid PostgreSQL operation like RENAME, DROP etc.

Let’s take some examples of using the ALTER SCHEMA statement to get a better understanding.

Example 1:
This example uses the ALTER SCHEMA statement to rename the schema geeksforgeeks to gfg:

ALTER SCHEMA geeksforgeeks
RENAME TO gfg;

To verify the change use the below statement:



SELECT 
  * 
FROM 
    pg_catalog.pg_namespace
ORDER BY 
    nspname;

Output:

Example 2:
The following example uses the ALTER SCHEMA statement to change the owner of the schema gfg to from Raju to postgres:

ALTER SCHEMA gfg
OWNER TO postgres;

To verify the change use the below statement:

SELECT 
  * 
FROM 
    pg_catalog.pg_namespace
ORDER BY 
    nspname;

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :