Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primary key in cassandra is unique?

It could be kind of lame but in cassandra has the primary key to be unique? For example in the following table:

CREATE TABLE users (   name text,   surname text,   age int,   adress text,   PRIMARY KEY(name, surname) ); 

So if is it possible in my database to have 2 persons in my database with the same name and surname but different ages? Which means same primary key..

like image 589
DarKAngeL Avatar asked Feb 13 '14 18:02

DarKAngeL


People also ask

What is primary key in Cassandra?

A primary key in Cassandra consists of one or more partition keys and zero or more clustering key components. The order of these components always puts the partition key first and then the clustering key.

Can we change primary key in Cassandra?

There is no way to change a primary key, as it defines how your data is physically stored. You can create a new table with the new primary key, copy data from the old one, and then drop the old table.

How do I create a unique key in Cassandra?

Use clustering and/or partitioning keys to add an unique constraint. To store unique values, create a separate table having your unique value as a key. Check if it exists by requesting this table before inserting a row.

Does primary key always have to be unique?

Primary key is always unique in every SQL. You dont have to explicitly define it as UNIQUE. On a side note: You can only have onePrimary key in a table and it never allows null values.


1 Answers

Yes the primary key has to be unique. Otherwise there would be no way to know which row to return when you query with a duplicate key.

In your case you can have 2 rows with the same name or with the same surname but not both.

like image 60
Daniel Avatar answered Oct 05 '22 03:10

Daniel