Cassandra的cqlsh操作

  1. 建库
CREATE KEYSPACE twitter WITH REPLICATION = { 'class': 'SimpleStrategy', 'replication_factor': 1};
  1. 建表
CREATE TABLE IF NOT EXISTS twitter.hotels (
id UUID,
name varchar,
address varchar,
primary key(id)
);
  1. 查询
cqlsh> desc keyspaces;

twitter      system         system_distributed  system_schema
system_auth  elastic_admin  system_traces     

cqlsh> use twitter ;
cqlsh:twitter> desc tables;

"_doc"  hotels
cqlsh:twitter> desc table "_doc"; #查看表结构
cqlsh:twitter> select * from hotels ;
#name不是primary key必须加allow filtering
cqlsh:twitter> SELECT * FROM hotels WHERE name='7天' allow filtering;
#使用contains 对list、set集合中的元素进行过滤
cqlsh:twitter> select * from "_doc" where user contains 'Jimmy' allow filtering;
// 使用contains key 对map集合进行过滤
cqlsh:twitter> select * from users where scores contains key 'english' allow filtering;
  1. 更新
    where必须为primary key字段

猜你喜欢

转载自blog.csdn.net/jiangshuanshuan/article/details/87874836