How to create Columnfamilies or Tables in Cassandra using cqlsh

Syntax for creating a table/columnfamily is:




Syntax for defining a column in the table is:
column_name column_data_type

Example to create a table is given below:

create table cassandrademo.users(
user_id int Primary Key,
user_name text,
user_email text,
user_pwd text

where user_id is the primary key field and cassandrademo is the keyspace name

You can see the table structure by using command:

describe table users;

Output is:

CREATE TABLE cassandrademo.users (
user_id int PRIMARY KEY,
user_email text,
user_name text,
user_pwd text
) WITH bloom_filter_fp_chance = 0.01
AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
AND comment = ''
AND compaction = {'min_threshold': '4', 'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32'}
AND compression = {'sstable_compression': ''}
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 = '99.0PERCENTILE';

The Primary Key is the combination of Partition Key and the identifier.

Leave a Reply

Your email address will not be published. Required fields are marked *