CREATE TABLE defines a new table in ClickHouse with chosen columns, data types, engine, and index settings.
CREATE TABLE lets you design storage for fast analytics—choosing column data types, primary key, partition keys, and an engine such as MergeTree for high-speed inserts and queries.
Start with the table name, list columns with types, pick an engine, then add ORDER BY and PARTITION BY clauses for optimal performance.
CREATE TABLE Customers
(
id UInt64,
name String,
email String,
created_at DateTime
) ENGINE = MergeTree()
ORDER BY id;
CREATE TABLE Orders
(
id UInt64,
customer_id UInt64,
order_date Date,
total_amount Decimal(10,2)
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(order_date)
ORDER BY (customer_id, id);
Yes—append IF NOT EXISTS to skip creation when the table is present.
CREATE TABLE OrderItems IF NOT EXISTS
(
id UInt64,
order_id UInt64,
product_id UInt64,
quantity UInt8
) ENGINE = MergeTree()
ORDER BY id
SETTINGS compression = 'ZSTD', ttl = toDateTime(order_id) + INTERVAL 30 DAY;
Use MergeTree for most workloads. ReplicatedMergeTree adds high availability, while ReplacingMergeTree deduplicates rows by a version column.
SHOW TABLES FROM default;
See below for troubleshooting tips and fixes.
Yes. It silently skips creation when the table already exists, avoiding errors in automated scripts.
No. You must create a new table with the desired engine and INSERT SELECT data into it.
Run DROP TABLE [IF EXISTS] table_name [ON CLUSTER cluster]; this removes data immediately unless SYNC option is used.