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..
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With