CREATE SCHEMA creates a user-defined .
The CREATE SCHEMA statement performs a schema change. For more information about how online schema changes work in CockroachDB, see .
Required privileges
- Only members of the
adminrole can create new schemas. By default, therootuser belongs to theadminrole. - To on a user-defined schema, a user must have the
GRANTprivilege on the schema and the privilege that they want to grant. - To create or interact with objects that depend on a user-defined schema, a user must have the
USAGEprivilege on the schema.
Syntax
Parameters
Example
Setup
To follow along, run to start a temporary, in-memory cluster with the sample dataset preloaded:Create a schema
CREATE SCHEMA statement is the owner of the schema. For example, suppose you created the schema as user root. root would be the owner of the schema.
Create a schema if one does not exist
Create two tables of the same name in different schemas
You can create tables of the same name in the same database if they are in separate schemas.Create a schema with authorization
To specify the owner of a schema, add anAUTHORIZATION clause to the CREATE SCHEMA statement:
CREATE SCHEMA statement with an AUTHORIZATION clause, the schema will be named after the user specified:
$user schema (i.e., a schema named after the current user). If no schema exists with the name of the current user, the public schema is used.
For example, suppose that you (i.e., the role of the current user root) to the max user:
max and creates two tables of the same name, in the same database, one in the max schema, and one in the public schema:
max then inserts some values into the accounts table, without specifying a schema:
max is the current user, all unqualified accounts table names resolve as max.accounts, and not public.accounts.

