Cassandra查询语言CQL的基本使用

在window环境下运行CQL语言要先安装python环境,在linux下不需要,cassandra内置了python。

1.查看python版本:python --version
2.运行pythod:python ./cqlsh

一. CQL定义语句:
keyspace:
3.查看创建keyspace的相关帮助:help create keyspace;
4.创建keyspace:create keyspace ks1 with replication = {'class':'SimpleStrategy','replication_factor':1};
5.查看keyspace的结构:desc keyspace ks1;
6.修改keyspace:alter keyspace ks1 with replication = {'class':'SimpleStrategy','replication_factor':2};
7.删除keyspace:drop keyspace ks1
8.切换到keyspace:use ks1

列族:
9.创建列族:
create table testtable(
name text,
age int,
profile text,
PRIMARY KEY(name)
);
10.查看创建的列族:desc table testtable
11.修改列族的comment内容: alter table testtable with comment = 'test';
12.给列族添加一列:alter table testtable add sex text;
13.删除列族的一列:alter table testtable drop sex;
14.删除列族:drop table testtable;
15.清空列族的数据:truncate testtable;

索引:
16.创建第二索引(该索引系统自动取名):create index on student(name);
17.删除索引:drop index student_name_idx;

自定义数据类型:
18.创建自定义数据类型:create type address( country text, province text, city text, road );
其他操作和列族的操作类似。

触发器:
19.创建触发器:

二. CQL数据操作语句(90%和关系型数据库相同,但是在CQL中的统计函数只能使用COUNT,并且出现在where关键字后面的属性只能
是primary key,复合主键只能是第一个属性出现,如果要出现的话必须加ALLOW filtering,非primary key的属性必须创建第二索引
才可以出现在where后面)
1.insert插入数据:insert into student(orderid,age,name,sex) values(10001,20,'zhangsan','man');
2.select查询语句:select * from student;
3.update更新语句:update student set name='lisi' where orderid=10001;
4.delete删除age列的数据:delete age from student where orderid=10001;
5.delete删除整行的数据:delete from student where orderid=10001;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值