Table in Apache Cassandra

Connect with

Apache Cassandra
Well, in Apache Cassandra, Keyspace is similar to schema in RDBMS and Coulum-family of Apache Cassandra is similar to table in RDBMS, but nowadays , we most of the time say Table in Cassandra. Apache Cassandra is very much flexible with different types of data, whether it is either semi-structured data or unstructured data. if you are new in Cassandra , you can visit our post: What is Apache Cassandra?

1. Create a Table in Apache Cassandra

CREATE TABLE users (
    user_id text PRIMARY KEY,
    emails set
    );

OR

create TABLE user (
   first_name varchar , 
   last_name varchar, 
   PRIMARY KEY (first_name)
   );

2. Creating a table with ID

If a table is accidentally dropped with DROP TABLE command, by using this option you can recreate the table and run a commitlog replay to retrieve the data.

CREATE TABLE users (
    user_id text PRIMARY KEY,
    emails set
    ) WITH ID='5a1c395e-b41f-11e5-9f22-ba0be0483c18';

3. Alter table in Cassandra

CREATE TABLE user (
  user_name varchar PRIMARY KEY, 
  bio ascii,
  );
ALTER TABLE user ALTER bio TYPE text;
ALTER TABLE user ALTER bio TYPE blob;

Adding a Column

ALTER TABLE user_keyspace.user ADD firstname text;

Drop a Column

ALTER TABLE user_keyspace.user DROP bio ;

4. Describe Table

DESCRIBE TABLE user;

5. References

  1. Datastax’s cqlsh

Similar Post which you may like

Your Comments are welcome to improve this post.


Connect with

Leave a Reply

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