PostgreSQL Create schema syntax, Alter schema

Create postgresql schema

Create schema syntax, Alter schema with examples.

Syntax

CREATE SCHEMA schema_name 
[ schema_element [ ... ] ];

CREATE SCHEMA AUTHORIZATION 
username [ schema_element [ ... ] ];

Example

CREATE SCHEMA test;

Create a schema for user user_1, 
and schema will be created 
automatically with the name _user_1:
CREATE SCHEMA AUTHORIZATION user_1;

Alter postgresql schema

Syntax

ALTER SCHEMA schema_name 
RENAME TO new_schema_name;

ALTER SCHEMA schema_name 
OWNER TO new_owner;

Example

ALTER SCHEMA test 
RENAME TO test_2;

ALTER SCHEMA test 
OWNER TO user_2;

Drop postgresql schema

Syntax

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

Example

DROP SCHEMA test CASCADE;