CREATE TABLE (CQL)

Creates a Cassandra table. The PRIMARY KEY defines the partition key (data location) and clustering columns (sort order within a partition). Design the table for your specific query patterns.

Syntax

cassandra
CREATE TABLE name (
  col type,
  PRIMARY KEY ((partition_key), clustering_col)
) WITH CLUSTERING ORDER BY (col DESC);

Example

cassandra
CREATE TABLE user_events (
  user_id    UUID,
  event_time TIMESTAMP,
  event_type TEXT,
  data       TEXT,
  PRIMARY KEY (user_id, event_time)
) WITH CLUSTERING ORDER BY (event_time DESC)
  AND default_time_to_live = 2592000;