Adding columns to tables

Let's say we want to allow our users to enter their location in the profile. To store a user's location, we need a new column in the users table; fortunately, it's perfectly straightforward to add a new column to an existing table:

ALTER TABLE "users" ADD "city_state" text; 

This query instructs Cassandra that we'd like to add a column named city_state, of type text, to the users table. It's identical to the equivalent operation in SQL, although the CQL ALTER TABLE statement is much more constrained in the operations it can perform.

Now let's check our table schema again:

DESC TABLE "users";

Here, we have used the command DESC, which is a short version of the DESCRIBE command. As we hoped, we've got a city_state ...

Get Learning Apache Cassandra - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.