ClickHouse/docs/en/sql-reference/statements/create/database.md

60 lines
1.9 KiB
Markdown
Raw Normal View History

---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/statements/create/database
sidebar_position: 35
sidebar_label: DATABASE
---
2022-06-02 10:55:18 +00:00
# CREATE DATABASE
Creates a new database.
``` sql
CREATE DATABASE [IF NOT EXISTS] db_name [ON CLUSTER cluster] [ENGINE = engine(...)] [COMMENT 'Comment']
```
2022-06-02 10:55:18 +00:00
## Clauses
2022-06-02 10:55:18 +00:00
### IF NOT EXISTS
2021-05-27 19:44:11 +00:00
If the `db_name` database already exists, then ClickHouse does not create a new database and:
- Doesnt throw an exception if clause is specified.
- Throws an exception if clause isnt specified.
2022-06-02 10:55:18 +00:00
### ON CLUSTER
ClickHouse creates the `db_name` database on all the servers of a specified cluster. More details in a [Distributed DDL](../../../sql-reference/distributed-ddl.md) article.
2022-06-02 10:55:18 +00:00
### ENGINE
By default, ClickHouse uses its own [Atomic](../../../engines/database-engines/atomic.md) database engine. There are also [Lazy](../../../engines/database-engines/lazy.md), [MySQL](../../../engines/database-engines/mysql.md), [PostgresSQL](../../../engines/database-engines/postgresql.md), [MaterializedMySQL](../../../engines/database-engines/materialized-mysql.md), [MaterializedPostgreSQL](../../../engines/database-engines/materialized-postgresql.md), [Replicated](../../../engines/database-engines/replicated.md), [SQLite](../../../engines/database-engines/sqlite.md).
2022-06-02 10:55:18 +00:00
### COMMENT
You can add a comment to the database when you are creating it.
The comment is supported for all database engines.
**Syntax**
``` sql
CREATE DATABASE db_name ENGINE = engine(...) COMMENT 'Comment'
```
**Example**
Query:
``` sql
CREATE DATABASE db_comment ENGINE = Memory COMMENT 'The temporary database';
SELECT name, comment FROM system.databases WHERE name = 'db_comment';
```
Result:
```text
┌─name───────┬─comment────────────────┐
│ db_comment │ The temporary database │
└────────────┴────────────────────────┘
```