noob_programmer
noob_programmer

Reputation: 9

How can we identify a unique record in Cassandra for tables which don't have a primary key defined?

I have Cassandra database and some tables within it. Tables don't have primary key / unique key / composite key defined. How can we identify a unique record in a table?

Like oracle has concept of ROWID , in same way do we have something for Cassandra database. N/A

Upvotes: 1

Views: 65

Answers (1)

Erick Ramirez
Erick Ramirez

Reputation: 16303

It isn't possible to create Cassandra tables without a primary key defined.

The partition key in the primary key dictates how each record is "partitioned" or distributed among nodes in the cluster. Without a partition key, Cassandra doesn't know how to store the data in the cluster.

Here's an example table that is partitioned by email address:

CREATE TABLE users_by_email (
    email text,
    firstname text,
    lastname text,
    PRIMARY KEY (email)
)

In this example, it will not be possible to read or write to the table without knowing a user's email address.

For more info on how Cassandra distributes data across nodes in a cluster, see Partitioners in Cassandra. There is also this short video on how Cassandra stores data in partitions (extracted from the DS201 Cassandra Foundations course at DataStax Academy). Cheers!

Upvotes: 1

Related Questions