forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Yang, Tong <yangtong2@huawei.com> Co-committed-by: Yang, Tong <yangtong2@huawei.com>
3.0 KiB
3.0 KiB
CREATE DATABASE: Creating a Database
This section describes the basic syntax and usage of the SQL statement for creating a ClickHouse database.
Basic Syntax
CREATE DATABASE [IF NOT EXISTS] Database_name [ON CLUSTER ClickHouse cluster name]
ClickHouse cluster name is default_cluster by default.

The syntax ON CLUSTER ClickHouse cluster name enables the Data Definition Language (DDL) statement to be executed on all instances in the cluster at a time. You can run the following statement to obtain the cluster name from the cluster field:
select cluster,shard_num,replica_num,host_name from system.clusters;
Example
-- Create a database named test. CREATE DATABASE test ON CLUSTER default_cluster; -- After the creation is successful, run the query command for verification. show databases; ┌─name───┐ │ default │ │ system │ │ test │ └──────┘
Parent topic: Common ClickHouse SQL Syntax