Search code examples
cassandraprimary-keycreate-table

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..


Solution

  • 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.