Updated on 2026-11-06 GMT+08:00

CREATE DATABASE

Overview

The CREATE DATABASE statement is used to create a database in the current catalog or a specified catalog. A database is a namespace under a catalog, which is used to organize and manage objects such as tables, views, and functions. After a database is created, you can use the USE statement to switch to the database for subsequent operations.

Application Scenarios

  • Project isolation: Create independent databases for different projects or service domains to logically isolate data.
  • Environment management: Create databases for different environments, such as development, testing, and production environments.
  • Permission partitioning: Divide access permissions at the database level to control the data visible to different users.

Notes and Constraints

  • The database name must be unique in the same catalog. If you want to create a database with the same name, use IF NOT EXISTS.
  • The attributes that can be set in the WITH clause depend on the catalog implementation. Different catalogs support different attributes.
  • A database can be created only in the current catalog. Cross-catalog database creation is not supported.
  • Before deleting a database, ensure that the database contains no tables or other objects, or use CASCADE to delete the database in cascading mode.

Syntax Structure

CREATE DATABASE [IF NOT EXISTS] [catalog_name.]db_name
[COMMENT database_comment]
WITH (key1=val1, key2=val2, ...)

Syntax Description

Parameter

Mandatory

Description

IF NOT EXISTS

No

Specifies that no error is reported when a database with the same name already exists. If this parameter is not specified and a database with the same name already exists, an exception is thrown.

catalog_name

No

Specifies the name of the target catalog. If this parameter is not specified, the current catalog is used.

db_name

Yes

Database name, which must be unique in the catalog. You are advised to use lowercase letters and underscores (_) in the name.

COMMENT

No

Comment of the database, which helps understand the database usage and service.

WITH

No

Sets database-level attributes in key-value pairs. The available attributes depend on the catalog implementation.

Usage Example

Example 1: Create a database.

CREATE DATABASE IF NOT EXISTS mydb COMMENT 'AI DataLake service database';

Example 2: Create a Paimon database with the WITH attribute.

CREATE DATABASE IF NOT EXISTS paimon_db
COMMENT 'Paimon metadata database'
WITH (
 'location' = 'obs://bucket/path/paimon-warehouse/paimon_db'
);