DROP SCHEMA statement¶
The DROP SCHEMA statement destroys a schema in the current catalog. Once destroyed, all the objects in the schema are also destroyed.
The default schema /default_schema cannot be dropped.
Note
An operation involving a non-default schema or an object in it requires access to the schema, either implicitly or through an explicit USAGE grant, as well as the privilege required for the operation. The schema access check and the privilege check for the requested operation are independent; satisfying one does not satisfy the other. Schema access control does not apply to temporary graphs or built-in procedures and functions. For more information, see Schema access control.
Prerequisites¶
- A schema is created. For more information, see CREATE SCHEMA.
- The schema to be destroyed contains no resource objects.
- To drop a schema, you must be granted to perform the action
DROPon the used schema. For more information, see Roles and privileges.
Syntax¶
- drop_schema_statement
drop_schema_statement ::=
'DROP' 'SCHEMA' ('IF EXISTS')? schema_reference
Parameters¶
IF EXISTS¶
This clause checks if the schema to be destroyed exists in the path. If it does not exist, the schema is not destroyed and no exception is thrown.
If you do not specify this clause, an exception is thrown if the schema to be destroyed does not exist in the path.
schema_reference¶
The reference to the path of the schema. It specifies the path of the schema to be destroyed.
The path is case-sensitive and must match the path of an existing schema. Both absolute and relative schema paths can be used in the statement.
Examples¶
Destroy a schema using absolute path¶
DROP SCHEMA IF EXISTS /test/my_schema1
The preceding example destroys the schema in the path /test/my_schema1 created in the Examples section of CREATE SCHEMA.
Destroy a schema using relative path¶
'''
// Create a schema
CREATE SCHEMA IF NOT EXISTS /test/my_schema1
'''
'''
// Set the schema for the current session
SESSION SET SCHEMA /test/my_schema1
'''
'''
// Create a schema using relative path
CREATE SCHEMA IF NOT EXISTS ../my_schema2
'''
'''
// Destroy a schema using relative path
DROP SCHEMA IF EXISTS ../my_schema2
'''
The preceding example destroys a schema in the path /test/my_schema2 when the schema in the current session is set to /test/my_schema1.