cqlsh:play> CREATE TABLE example (userid int, date int, name text, PRIMARY KEY (userid, date));
cqlsh:play> INSERT INTO example (userid, date, name) VALUES (1, 20200530, 'a');
cqlsh:play> INSERT INTO example (userid, date, name) VALUES (1, 20200531, 'a');
cqlsh:play> INSERT INTO example (userid, date, name) VALUES (2, 20200531, 'a');
cqlsh:play> SELECT * FROM example;
userid | date | name
--------+----------+------
1 | 20200530 | a
1 | 20200531 | a
2 | 20200531 | a
(3 rows)
cqlsh:play> INSERT INTO example (userid, date, name) VALUES (2, 20200531, 'b');
cqlsh:play> SELECT * FROM example;
userid | date | name
--------+----------+------
1 | 20200530 | a
1 | 20200531 | a
2 | 20200531 | b
(3 rows)
cqlsh:play>
1条答案
按热度按时间juud5qan1#
单个分区密钥(不带群集密钥)无效
primary key
必须是独一无二的。一
partition key
+clustering key
必须是唯一的,但这并不意味着分区键或集群键必须是唯一的。您可以插入
(a,b)(第一条记录)
(a,c)(与第一条记录的分区键相同)
(d,b)(与第一条记录相同的聚类键)
当您再次插入(a,b)时,它将更新现有主键的非主键值。
在下面的示例中
userid
是分区键和date
是群集键。