Quantcast
Channel: Welcome To TechBrothersIT
Viewing all articles
Browse latest Browse all 1876

Drop Column from Table in Cassandra - Cassandra / CQL Tutorial

$
0
0

Drop Column from Table in Cassandra

Cassandra let you drop the column from table if you would like to do that. You can not drop the column which is part of Primary key. If you will try to drop column which is part of primary key, you will get below error.

InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot drop PRIMARY KEY part columnName"
 

 

Syntax:

CQLSH:techbrotherstutorials>ALTER TABLE tablename DROP columnname;

 

Example:

Let's create Employee table by using below script.

CQLSH:techbrotherstutorials>CREATE TABLE employee 
             ( 
                          employeeid UUID PRIMARY KEY, 
                          fname TEXT, 
                          lname TEXT, 
                          address TEXT, 
                          age TINYINT 
             );

 

If we would like to drop the age column, we can use below script.

CQLSH:techbrotherstutorials>ALTER TABLE employee DROP age;

Viewing all articles
Browse latest Browse all 1876

Trending Articles