Operations with schemas
-
CREATE SCHEMA— Create a new schema -
ALTER SCHEMA— Change schema attributes -
DROP SCHEMA— Delete a schema -
SET SCHEMA— Set default schema -
SHOW SCHEMA— Output default schema -
SHOW SCHEMAS— Output a list of all schemas
Create a new schema
CREATE [OR REPLACE] SCHEMA [IF NOT EXISTS] <schema_name>
Creates a new schema with the specified name.
If the OR REPLACE modifier is specified, the final action is equivalent to deleting the existing schema with all objects in it and creating a new schema with the same name.
The optional IF NOT EXISTS modifier restricts the query to only those cases in which the specified object does not already exist.
| The modifiers are mutually exclusive. Specifying them both will result in an error. |
Change schema attributes
ALTER SCHEMA [IF EXISTS] <schema_name> RENAME TO <new_name>;
Modifies the pattern with the specified action.
Currently, only one action is available for changing schemas:
-
The
RENAME TOaction renames the schema to the specified name<new_name>. All attributes and permissions are retained.
The optional IF EXISTS modifier restricts the query to only those cases in which the specified object exists.
Delete a schema
DROP SCHEMA [IF EXISTS] <schema_name>;
Deletes the schema with the specified name.
The optional IF EXISTS modifier restricts the query to only those cases in which the specified object exists.
Set default schema
SET SCHEMA = <schema_name>;
Sets the default schema for the current session.
If a default schema is set, all unqualified table names (without an explicit schema specification) are interpreted using the set schema. Tables specified using qualified names are not affected by the default schema.
If no default schema is set, all unqualified table names are interpreted as belonging to the public schema.
Setting the default schema applies only to the current session; it does not affect other sessions and is reset when the session ends.
To check the default schema, run SHOW SCHEMA.
|