博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Cassandra查询语言CQL的基本使用
阅读量:7251 次
发布时间:2019-06-29

本文共 1497 字,大约阅读时间需要 4 分钟。

在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;

转载地址:http://inhbm.baihongyu.com/

你可能感兴趣的文章
UVAoj 11324 - The Largest Clique(tarjan + dp)
查看>>
使用Matplotlib绘制正余弦函数、抛物线
查看>>
四位辉光管时钟-学长毕设
查看>>
大话RAC介质恢复---联机日志损坏
查看>>
oracle 内存分配和调优 总结
查看>>
移植最新版libmemcached到VC++的艰苦历程和经验总结(上)
查看>>
诡异的bug: tcsh陷入死循环
查看>>
java-第一章-上机练习-04
查看>>
Active Directory 基础 (1)
查看>>
xml地图生成网址
查看>>
Python 练习1
查看>>
TCExam文件代码注释分析(后台首页admin/code/index.php)
查看>>
Finereport在企业级BI分析中的应用
查看>>
linux内核参数注释与优化
查看>>
linux 2.6x内核升级
查看>>
pxe
查看>>
NFS网络文件系统安装
查看>>
网页嵌入自动生成当前网页二维码图片代码
查看>>
Linux时间同步服务
查看>>
Python基础-----列表、元组、集合(2)
查看>>