Like most databases, ClickHouse logically groups tables into databases. Use theDocumentation Index
Fetch the complete documentation index at: https://private-7c7dfe99-page-updates.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
CREATE DATABASE command to create a new database in ClickHouse:
CREATE TABLE to define a new table. If you don’t specify the database name, the table will be in the
default database.
The following table named my_first_table is created in the helloworld database:
my_first_table is a MergeTree table with four columns:
user_id: a 32-bit unsigned integermessage: aStringdata type, which replaces types likeVARCHAR,BLOB,CLOBand others from other database systemstimestamp: aDateTimevalue, which represents an instant in timemetric: a 32-bit floating point number
The table engine determines:
- How and where the data is stored
- Which queries are supported
- Whether or not the data is replicated
A brief intro to primary keys
Before you go any further, it is important to understand how primary keys work in ClickHouse (the implementation of primary keys might seem unexpected!):- primary keys in ClickHouse are not unique for each row in a table
SELECT queries.
The primary key can be defined using the PRIMARY KEY parameter. If you define a table without a PRIMARY KEY specified,
then the key becomes the tuple specified in the ORDER BY clause. If you specify both a PRIMARY KEY and an ORDER BY, the primary key must be a prefix of the sort order.
The primary key is also the sorting key, which is a tuple of (user_id, timestamp). Therefore, the data stored in each
column file will be sorted by user_id, then timestamp.