CQL DDL: ALTER TABLE statement
Learn CQL DDL operation to ALTER a table in Apache Cassandra with syntax and best practices.
In this lesson, we will cover the basic syntax of CQL Data Definition Language (DDL) statements for altering an Apache Cassandra table, including adding, removing, and renaming columns, as well as modifying table options. To demonstrate, we will create and work with a simple courses
table using native data types and a single-column primary key. We will add complexity to the statements, as the course proceeds.
The ALTER TABLE
command
The ALTER TABLE
command is used to alter an existing table. A table’s primary key cannot be altered. ALTER TABLE
supports the following operations:
The ADD
operation
The ADD
operation adds one or more new column(s) to the table. If a column with the same name already exists in the table, the statement will return an error. The error may be avoided by the inclusion of the IF NOT EXISTS
directive before the column name, which makes the statement a no-op. Multiple columns may be added if a comma-separated list is provided.
Get hands-on with 1300+ tech skills courses.