Apache Cassandra 1.2 Documentation

Altering a table to add columns

The ALTER TABLE command adds new columns to a table. For example, to add a coupon_code column with the varchar data type to the users table:

cqlsh:demodb> ALTER TABLE users ADD coupon_code varchar;

This creates the column metadata and adds the column to the table schema, but does not update any existing rows.

Altering column metadata

Using ALTER TABLE, you can change the data type of a column after it is defined or added to a table. For example, to change the coupon_code column to store coupon codes as integers instead of text, change the data type as follows:

cqlsh:demodb> ALTER TABLE users ALTER coupon_code TYPE int;

Only newly inserted values, not existing coupon codes are validated against the new type.