DROP SCHEMA
DROP SCHEMA
— remove a schema
Syntax
DROP SCHEMA name [ CASCADE | RESTRICT ] [ IF EXISTS ];
DROP SCHEMA [ CASCADE | RESTRICT] [ IF EXISTS ] name;
Description
DROP SCHEMA
removes schemas from the database.
See CREATE SCHEMA
for information on how to create a schema.
Parameters
name
-
Name of the schema
CASCADE
-
Automatically drops objects such as tables or stored procedures, that are contained in the schema. This option can be used to forcibly drop all related schema, if required. See Dropping a Non-Empty Schema.
It is possible for DROP SCHEMA CASCADE
to fail if the transaction isolation level isCONSISTENT READ
and objects are created concurrently in the schema by other transactions. In this case, the "can’t find <object> name" error message is returned, where object is the type of the object created concurrently (for example, table). RESTRICT
-
Refuse to drop the schema if it contains any objects. This is the default.
IF EXISTS
-
If the schema does not exist and you specify
IF EXISTS
, NuoDB does not generate an error. Otherwise, if the schema does not exist, an error is generated.
Example
- Example 1: Creating an object in a schema.
CREATE SCHEMA schema1;
CREATE TABLE schema1.test_table (column1 INTEGER);
- Example 2: Dropping a Non-Empty Schema.
DROP SCHEMA schema1;
Error 42000: schema "SCHEMA1" is not empty and cannot be dropped, it has 1 table, 0 domains, 0 sequences, 0 roles, 0 procedures and 0 functions. CASCADE option can be used to forcibly drop the schema and all related content.
DROP SCHEMA schema1 CASCADE;