Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra - unique constraint on row key

Tags:

cassandra

I would like to know whenever it is possible in Cassandra to specify unique constrain on row key. Something similar to SQL Server's ADD CONSTRAINT myConstrain UNIQUE (ROW_PK)

In case of insert with already existing row key, the existing data will be not overwritten, but I receive kind of exception or response that update cannot be performed due to constrain violation.

Maybe there is a workaround for this problem - there are counters which updates seams to be atomic.

like image 427
Maciej Miklas Avatar asked Nov 16 '11 15:11

Maciej Miklas


People also ask

How do I create a unique key in Cassandra?

You can't. It's not a relational DB. 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.

Does partition key have to be unique Cassandra?

Each table demands a unique primary key. In Cassandra, a primary key consists of one or more partition keys and may include clustering key components. The Apache Cassandra partition key always precedes the clustering key since its hashed value determines which node will store the data.

How do you use distinct in Cassandra?

Use the DISTINCT keyword to return only distinct (different) values of partition keys. The FROM clause specifies the table to query. You may want to precede the table name with the name of the keyspace followed by a period (.). If you do not specify a keyspace, Cassandra queries the current keyspace.

Is unique key a constraint?

A unique constraint is the rule that the values of a key are valid only if they are unique. A key that is constrained to have unique values is called a unique key . A unique constraint is enforced by using a unique index.


1 Answers

Lightweight transactions?

http://www.datastax.com/documentation/cassandra/2.0/cassandra/dml/dml_ltwt_transaction_c.html

INSERT INTO customer_account (customerID, customer_email) VALUES (‘LauraS’, ‘[email protected]’) IF NOT EXISTS;

like image 97
Van Thoai Nguyen Avatar answered Sep 28 '22 05:09

Van Thoai Nguyen