Was this page helpful?
Primary Keys¶
The primary key can be made up of two parts: the partition key and optional
clustering columns. The user_id
column is the partition key in this example.
It determines how data gets distributed across the cluster.
Additional columns, if present, can be specified as clustering columns, which determine the internal sorting of data within a partition.
CREATE TABLE my_keyspace.orders (
order_id uuid,
product_id uuid,
quantity int,
PRIMARY KEY (order_id, product_id)
);
In this example, order_id
is the partition key, and product_id
is
the clustering key.
Partitions are determined by the partition key, a part of the primary key.
Data is distributed across nodes based on the partition key. In the orders
table, order_id
determines the partition.