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