How to Create a Table in ClickHouse
Last updated July 25, 2026 · By the SaturnSQL team
Use CREATE TABLE with an ENGINE clause; MergeTree is the standard engine for analytics tables. Unlike most databases, MergeTree tables require an ORDER BY clause, which defines the sort key used for data skipping, so pick the columns you filter by most.
CREATE TABLE events
(
event_time DateTime,
user_id UInt64,
event_type LowCardinality(String),
url String
)
ENGINE = MergeTree
ORDER BY (event_type, event_time);Optional partitioning
PARTITION BY splits data into separately managed chunks, which makes dropping old data cheap. Monthly partitions are a common default; avoid high-cardinality partition keys.
CREATE TABLE pageviews
(
event_time DateTime,
user_id UInt64,
url String
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(event_time)
ORDER BY (user_id, event_time);ORDER BY is a sort key, not a uniqueness constraint: ClickHouse happily stores duplicate keys. If you need last-write-wins semantics, use ReplacingMergeTree instead.
Run this in SaturnSQL
SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.
Try it free