Cloud

CREATE SCHEMA

The CREATE SCHEMA statement creates a SQL schema in the Redpanda SQL database. For what a schema holds and when to use one, see SQL Schemas.

Syntax

CREATE SCHEMA [IF NOT EXISTS] schema_name;
  • IF NOT EXISTS: Optional. If a schema with the same name already exists, the statement returns no error. The statement does not change the existing schema.

  • schema_name: Name of the schema to create.

Behavior

  • The role that creates the schema becomes its owner. To transfer ownership, use ALTER SCHEMA …​ OWNER TO.

  • If the schema already exists and you omit IF NOT EXISTS, the statement fails with Schema: <schema_name> already exists.

Permissions

Only a superuser can create a schema. The CREATE SCHEMA statement requires the CREATE privilege on the database. You cannot grant this privilege to other roles. In Redpanda Cloud, a user with the SQL: Manage permission is a superuser. See Manage access to Redpanda SQL.

To let other users create views in a schema, grant them the USAGE and CREATE privileges on the schema. See GRANT.

Examples

Create a schema named analytics:

CREATE SCHEMA analytics;

Create the schema only if it does not exist:

CREATE SCHEMA IF NOT EXISTS analytics;

Let a user create views in the analytics schema:

GRANT USAGE, CREATE ON SCHEMA analytics TO "alice@example.com";