Adding columns to tables
Let's say we want to allow our users to enter their location in the profile. To store users' 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:
DESCRIBE TABLE "users";
As we hoped, we've got a city_state
column in the schema. I've omitted the table properties for brevity: