`
liyonghui160com
  • 浏览: 762258 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Cassandra CQL语法介绍

阅读更多

 

 

1. 创建

keyspace  CREATE KEYSPACE twissandra WITHstrategy_class = 'SimpleStrategy' 

AND strategy_options:replication_factor = '1';  创建一个名为twissandra的keyspace,副本策略SimpleStrategy,复制因子

 

2. 创建Column family 

cqlsh> USE twissandra;  cqlsh> CREATE COLUMNFAMILY users (

创建一个名为

users的

column family  ...  KEY varchar PRIMARY KEY,

该columnfamily下有一个Key和5列  ...  passwordvarchar, ...  gendervarchar,   ...  session_tokenvarchar, ...  statevarchar,  ...  birth_yearbigint); 

 

3.插入和检索Columns  cqlsh> INSERT INTO users (KEY, 

password) VALUES ('jsmith', 'ch@ngem3a')  USING TTL 86400;向passwod这一列插入数据  cqlsh> SELECT * FROM users WHERE KEY='jsmith'; u'jsmith' | u'password',u'ch@ngem3a' | u'ttl', 86400 3.

 向Column family中增加Column  cqlsh> ALTER TABLE users ADD coupon_codevarchar; 注意:其他已经存在的列不会进行更新。 

 

4. 更改Column的元数据

  cqlsh> ALTER TABLE users ALTER coupon_code TYPE int; 注意:已经存在的数据不会转成此类型,新插入的数据才是该类型的。

5. 使用TTL

属性设置列的到期时间 

cqlsh> UPDATE users USING TTL 432000 SET 

'password'='ch@ngem3a' 

WHERE KEY='jsmith';更新密码列的到期时间为5天。 

 

6.

 删除列元数据  cqlsh> ALTER TABLE users DROP coupon_code; 

 

7. 索引Column  cqlsh> CREATE INDEX state_key ON users (state);  cqlsh> CREATE INDEX birth_year_key ON users (birth_year); 

 

8. 删除列或者行  cqlsh> DELETE session_token FROM users where KEY='jsmith'; cqlsh> DELETE FROM users where KEY='jsmith'; 9. 删除columnfamily和keyspace 

 

cqlsh> DROP COLUMNFAMILY users; cqlsh> DROP KEYSPACE twissandra; 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics