CQL for Cassandra 1.2

Using a compound primary key

Use a compound primary key when you want to create columns that you can query to return sorted results.


To create a table having a compound primary key, use two or more columns as the primary key.
  empID int,
  deptID int,
  first_name varchar,
  last_name varchar,
  PRIMARY KEY (empID, deptID));
The compound primary key is made up of the empID and deptID columns in this example. The empID acts as a partition key for distributing data in the table among the various nodes that comprise the cluster. The remaining component of the primary key, the deptID, acts as a clustering mechanism and ensures that the data is stored in ascending order on disk (much like a clustered index in Microsoft SQL Server).