更新时间:2022-09-21 21:38:57
Cassandra之中一共包含下面5种Key:
1
2
3
4
5
6
7
8
9
10
11
12
|
-- 一列
create table *** (
key text PRIMARY KEY,
data text
);
-- 复合列
create table *** (
key_part_one text,
key_part_two int,
data text,
PRIMARY KEY(key_part_one, key_part_two)
);
|
Clustering Key : 主要用于进行Range Query. 并且使用的时候需要按照建表顺序进行提供信息!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
-- 创建表
-- 注意state 这个field
CREATE TABLE users (
mainland text,
state text,
uid int,
name text,
zip int,
PRIMARY KEY ((mainland), state, uid)
)
-- 插入一些值
insert into users (mainland, state, uid, name, zip)
VALUES ( 'northamerica', 'washington', 1, 'john', 98100);
xxxx more
insert into users (mainland, state, uid, name, zip)
VALUES ( 'southamerica', 'argentina', 6, 'alex', 10840);
|
1
|
select * from users where mainland = 'northamerica' and state > 'ca' and state < 'ny';
|