cassandracqlcqlshthrift-protocolnosql

cassandra:: can i create a table without a primarykey?


Now i'm learning Cassandra, so i got a table without primary key. But it has some indexes.

So this is my doubt, can i create a table without primary key.?

CREATE TABLE subscription (subscriberid varchar,productid varchar,panaccessproductid varchar,operatorproductid varchar,price float,fallback varchar,paymenttype varchar,operatorid varchar,subscriptiontype varchar,expiry timestamp,subscriptionstatus varchar,created timestamp);

There is no primarykey and subscriberid,productid,operatorid and subscriptiontype are indexes. Is this possible?

From the documentation

Primary Key:: A primary key identifies the location and order of data storage. The primary key is defined at table creation time and cannot be altered. If the primary key must be changed, a new table schema is created and the data is written to the new table. Cassandra is a partition row store, and a component of the primary key, the partition key, identifies which node will hold a particular table row. At the minimum, the primary key must consist of a partition key. Composite partition keys can split a data set so that related data is stored on separate partitions. Compound primary keys include clustering columns which order the data on a partition. The definition of a table's primary key is critical in Cassandra. Carefully model how data in a table will be inserted and retrieved before choosing which columns will define the primary key. The size of the partitions, the order of the data within partitions, the distribution of the partitions amongst the nodes of the cluster - all of these considerations determine selection of the best primary key for a table.


Solution

  • Plain answer is no, primary key is mandatory