Cassandra - 行键的唯一约束 [英] Cassandra - unique constraint on row key

查看:29
本文介绍了Cassandra - 行键的唯一约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道何时可以在 Cassandra 中对行键指定唯一约束.类似于 SQL Server 的 ADD CONSTRAINT myConstrain UNIQUE (ROW_PK)

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.

推荐答案

Cassandra - 可以在主键约束的帮助下实现唯一约束.您需要将所有列作为主键,那些您希望是唯一的.Cassandra 将自行解决其余的问题.

Cassandra - a unique constraint can be implemented with the help of a primary key constrain. You need to put all the columns as primary key, those you want to be unique. Cassandra will tackle the rest on it own.

CREATE TABLE users (firstname text, lastname text, age int, 
email text, city text, PRIMARY KEY (firstname, lastname));

这意味着当firstnamelastname 相同时,Cassandra 不会在这个users 表中插入两个不同的行.

It means Cassandra will not insert two different rows in this users table when firstname and lastname are the same.

这篇关于Cassandra - 行键的唯一约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆