Friday 24 January 2020

Cassandra: ALTER TABLE: Change table definition


‘ALTER TABLE’ command is used to change the table definition.

Syntax
<alter-table-stmt> ::= ALTER (TABLE | COLUMNFAMILY) <tablename> <instruction>

<instruction> ::= ADD   <identifier> <type>
                | ADD   ( <identifier> <type> ( , <identifier> <type> )* )
                | DROP  <identifier>
                | DROP  ( <identifier> ( , <identifier> )* )
                | WITH  <option> ( AND <option> )*

Example

'ALTER TABLE employee ADD lastName VARCHAR;' adds new column lastName to the table 'employee'.
cqlsh> CREATE keyspace cassandratutorial WITH REPLICATION = 
   ... { 
   ... 'class' : 'SimpleStrategy', 
   ... 'replication_factor' : 1 
   ... };
cqlsh> 
cqlsh> USE cassandratutorial;
cqlsh:cassandratutorial> 
cqlsh:cassandratutorial> CREATE TABLE IF NOT EXISTS employee (
                     ...   id INT, 
                     ...   firstName VARCHAR,
                     ...   PRIMARY KEY((id, firstName))
                     ... ) WITH comment = 'Table to store Employee information';
cqlsh:cassandratutorial> 
cqlsh:cassandratutorial> DESCRIBE employee;

CREATE TABLE cassandratutorial.employee (
    id int,
    firstname text,
    PRIMARY KEY ((id, firstname))
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = 'Table to store Employee information'
    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';

cqlsh:cassandratutorial> 
cqlsh:cassandratutorial> ALTER TABLE employee ADD lastName VARCHAR;
cqlsh:cassandratutorial> 
cqlsh:cassandratutorial> DESCRIBE employee;

CREATE TABLE cassandratutorial.employee (
    id int,
    firstname text,
    lastname text,
    PRIMARY KEY ((id, firstname))
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = 'Table to store Employee information'
    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





Previous                                                    Next                                                    Home

No comments:

Post a Comment