CREATE SCHEMA
Defines a schema.
Syntax
CREATE SCHEMA [ IF NOT EXISTS ] [{ namespace. | database. }]schema
[ AUTHORIZATION username]
[ DEFAULT { INCLUDE | EXCLUDE } [ SCHEMA ] PRIVILEGES ]
[ DISK_QUOTA quota ]
Parameters
IF NOT EXISTS
If an object with the same name exists, return without creating the object. If you do not use this directive and the object already exists, Vertica returns with an error message.
The
IF NOT EXISTS
clause is useful for SQL scripts where you might not know if the object already exists. The ON ERROR STOP directive can be helpful in scripts.namespace
- For Eon Mode databases, namespace under which to create the schema. If unspecified, the schema is created under the
default_namespace
. database
- For Enterprise Mode databases, name of the database. If specified, it must be the current database.
schema
- Name of the schema to create, with the following requirements:
-
Must be unique among all other schema names in the
namespace
under which the schema is created. -
Must comply with keyword restrictions and rules for Identifiers.
-
Cannot begin with
v_
; this prefix is reserved for Vertica system tables.
-
AUTHORIZATION
username
- Valid only for superusers, assigns ownership of the schema to another user. By default, the user who creates a schema is also assigned ownership.
After you create a schema, you can reassign ownership to another user with
ALTER SCHEMA
. DEFAULT {INCLUDE | EXCLUDE} [SCHEMA] PRIVILEGES
Specifies whether to enable or disable default inheritance of privileges for new tables in the specified schema:
-
EXCLUDE SCHEMA PRIVILEGES
(default): Disables inheritance of schema privileges. -
INCLUDE SCHEMA PRIVILEGES
: Specifies to grant tables in the specified schema the same privileges granted to that schema. This option has no effect on existing tables in the schema.
If you omit
INCLUDE PRIVILEGES
, you must explicitly grant schema privileges on the desired tables.For more information see Enabling schema inheritance.
-
DISK_QUOTA
quota
- String, an integer followed by a supported unit: K, M, G, or T. Data-load, DML, and ILM operations that increase the schema's usage beyond the set quota fail. For details, see Disk quotas.
If not specified, the schema has no quota.
Privileges
-
Superuser (required to set disk quota)
Supported sub-statements
CREATE SCHEMA
can include one or more sub-statements—for example, to create tables or projections within the new schema. Supported sub-statements include:
-
CREATE TABLE / CREATE TEMPORARY TABLE
- GRANT statements
-
CREATE PROJECTION
-
CREATE SEQUENCE
-
CREATE TEXT INDEX
-
CREATE VIEW
CREATE SCHEMA
statement and all sub-statements are treated as a single transaction. If any statement fails, Vertica rolls back the entire transaction. The owner of the new schema is assigned ownership of all objects that are created within this transaction.
For example, the following CREATE SCHEMA
statement also grants privileges on the new schema, and creates a table and view of that table:
Examples
Create schema s1
:
Create schema s2
if it does not already exist:
In an Eon Mode database, create schema s3
in namespace n1
:
In an Eon Mode database, create schema s3
in the default_namespace
:
If the schema already exists, Vertica returns a rollback message:
Create table t1
in schema s1
, then grant users Fred
and Aniket
access to all existing tables and all privileges on table t1
:
Enable inheritance on new schema s3
so all tables created in it automatically inherit its privileges. In this case, new table s3.t2
inherits USAGE, CREATE, and SELECT privileges, which are automatically granted to all database users: