zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    JavaScript学习笔记(十六) XMLHttpRequest
    Zabbix 3.0 安装笔记
    jetty端口灵活配置方法
    IDEA15入门常用设置
    [转] 填石头——时间管理
    [转]关于产品的落地
    [转]Netbeans IDE默认UTF-8编码
    如何解决SSH连接Linux超时自动断开?
    ActiveMQ部署步骤和后台管理网站Service Unavailable问题解决笔记
    [转]Maven2中snapshot快照库的使用
  • 原文地址:https://www.cnblogs.com/longshiyVip/p/4859143.html
Copyright © 2011-2022 走看看