Cassandra - 表操作

  1. 創建表
CREATE (TABLE | COLUMNFAMILY) <tablename>
('<column-definition>' , '<column-definition>')
(WITH <option> AND <option>)
qlsh:test01> CREATE TABLE test(
          ...     id int PRIMARY KEY,
          ...     col1 text,
          ...     col2 text,
          ...     col3 timestamp
          ... );
cqlsh:test01> DESC test;
CREATE TABLE test01.test (
    id int PRIMARY KEY,
    col1 text,
    col2 text,
    col3 timestamp
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
  1. 修改表
ALTER (TABLE | COLUMNFAMILY) <tablename> <instruction>
cqlsh:test01> ALTER TABLE test ADD col4 uuid ;
cqlsh:test01> ALTER TABLE test DROP COL2;

  1. 刪除表
DROP TABLE <tablename>
cqlsh:test01> DROP TABLE emp ;
cqlsh:test01> DESCRIBE TABLES ;
<empty>

  1. 截斷表
TRUNCATE <tablename>
cqlsh:test01> TRUNCATE test;
  1. 創建索引
CREATE INDEX <identifier> ON <tablename>
cqlsh:test01> CREATE INDEX ON test(col1);
cqlsh:test01> DESC test;
CREATE TABLE test01.test (
    id int PRIMARY KEY,
    col1 text,
    col2 text,
    col3 timestamp,
    col4 uuid
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
CREATE INDEX test_col1_idx ON test01.test (col1);
  1. 刪除索引
DROP INDEX <identifier>
cqlsh:test01> DROP INDEX test_col1_idx ;
cqlsh:test01> DESC test;
CREATE TABLE test01.test (
    id int PRIMARY KEY,
    col1 text,
    col2 text,
    col3 timestamp,
    col4 uuid
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
  1. 批處理
BEGIN BATCH
<insert-stmt>/ <update-stmt>/ <delete-stmt>
APPLY BATCH
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章