v.23.7New Feature

Create Table Enhanced with PRIMARY KEY Syntax in Column Definition

Create table now supports PRIMARY KEY syntax in column definition. Columns are added to primary index in the same order columns are defined. #51881 (Ilya Yatsishin).
The CREATE TABLE statement now supports defining PRIMARY KEY constraints directly in column definitions, where columns are added to the primary key in the order they are declared.

Why it matters

This feature simplifies table schema declarations by allowing users to specify primary key columns inline with their definitions. It improves readability and clarity by eliminating the need for a separate primary key clause, and ensures the primary key columns follow the declaration order.

How to use it

When creating a table, add PRIMARY KEY directly after column definitions to include them in the primary key. The primary key columns will be indexed in the order they appear. For example:

CREATE TABLE example (
id UInt32 PRIMARY KEY,
name String PRIMARY KEY,
age UInt8
) ENGINE = MergeTree();