CREATE SCHEMA
Overview
The CREATE SCHEMA statement creates a new schema within the current workspace. A schema is a logical namespace for database objects (tables, views, functions, etc.), used to group and manage data.
Syntax
Parameters
| Parameter | Required | Description |
|---|---|---|
schema_name | Yes | Name of the new schema, must be unique within the same workspace |
IF NOT EXISTS | No | If the schema already exists, skip without error |
COMMENT 'comment' | No | Add a descriptive comment for the schema |
Examples
Example 1: Create a basic schema
Example 2: Create a schema with a comment
Example 3: Use IF NOT EXISTS to avoid duplicate creation errors
After execution, verify the result using SHOW SCHEMAS:
Sample output (partial):
Example 4: View schema details
Sample output:
Notes
- Schema names must be unique within the same workspace. Duplicate creation will cause an error, so using
IF NOT EXISTSis recommended. - Schema names support letters, digits, and underscores, are case-insensitive, and lowercase letters are recommended.
- After creating a schema, you can use
ALTER SCHEMAto modify its comment or properties, andDROP SCHEMAto delete it.
Required Privileges
The user executing CREATE SCHEMA must have the privilege to create a schema in the current workspace.
