---
title: "ALTER TABLE"
url: "https://docs.yugabyte.com/stable/api/ycql/ddl_alter_table/"
---

# ALTER TABLE

Use the ALTER TABLE statement to change the schema or definition of an existing table.

## Synopsis

Use the `ALTER TABLE` statement to change the schema or definition of an existing table. It allows adding, dropping, or renaming a column as well as updating a table property.

## Syntax

### Diagram

ALTERTABLE[table\_name](/stable/api/ycql/grammar_diagrams#table-name)ADD,[column\_name](/stable/api/ycql/grammar_diagrams#column-name)[column\_type](/stable/api/ycql/grammar_diagrams#column-type)DROP,[column\_name](/stable/api/ycql/grammar_diagrams#column-name)RENAME,[column\_name](/stable/api/ycql/grammar_diagrams#column-name)TO[column\_name](/stable/api/ycql/grammar_diagrams#column-name)WITHAND[property\_name](/stable/api/ycql/grammar_diagrams#property-name)=[property\_literal](/stable/api/ycql/grammar_diagrams#property-literal)

### Grammar

```ebnf
alter_table ::= ALTER TABLE table_name alter_operator [ alter_operator ...]

alter_operator ::= add_op | drop_op | rename_op | property_op

add_op ::= ADD column_name column_type [ ',' column_name column_type ...]

drop_op ::= DROP column_name [ ',' column_name ...]

rename_op ::= RENAME column_name TO column_name [ ',' column_name TO column_name ...]

property_op ::= WITH property_name '=' property_literal [ AND property_name '=' property_literal ...]
```

Where

- `table_name`, `column_name`, and `property_name` are identifiers (`table_name` may be qualified with a keyspace name).
- `property_literal` is a literal of either [boolean](/stable/api/ycql/type_bool "boolean"), [text](/stable/api/ycql/type_text "text"), or [map](/stable/api/ycql/type_collection "map") data type.

## Semantics

- An error is raised if `table_name` does not exist in the associated keyspace.
- Columns that are part of `PRIMARY KEY` cannot be altered.
- When adding a column, its value for all existing rows in the table defaults to `null`.
- After dropping a column, all values currently stored for that column in the table are discarded (if any).

## Examples

### Add a column to a table

```sql
ycqlsh:example> CREATE TABLE employees (id INT, name TEXT, salary FLOAT, PRIMARY KEY((id), name));
```

```sql
ycqlsh:example> ALTER TABLE employees ADD title TEXT;
```

```sql
ycqlsh:example> DESCRIBE TABLE employees;
```

Following result would be shown.

```output
CREATE TABLE example.employees (
    id int,
    name text,
    salary float,
    title text,
    PRIMARY KEY (id, name)
) WITH CLUSTERING ORDER BY (name ASC);
```

### Remove a column from a table

```sql
ycqlsh:example> ALTER TABLE employees DROP salary;
```

```sql
ycqlsh:example> DESCRIBE TABLE employees;
```

Following result would be shown.

```output
CREATE TABLE example.employees (
    id int,
    name text,
    title text,
    PRIMARY KEY (id, name)
) WITH CLUSTERING ORDER BY (name ASC);
```

### Rename a column in a table

```sql
ycqlsh:example> ALTER TABLE employees RENAME title TO job_title;
```

```sql
ycqlsh:example> DESCRIBE TABLE employees;
```

Following result would be shown.

```output
CREATE TABLE example.employees (
    id int,
    name text,
    job_title text,
    PRIMARY KEY (id, name)
) WITH CLUSTERING ORDER BY (name ASC);
```

### Update a table property

You can do this as follows:

```sql
ycqlsh:example> ALTER TABLE employees WITH default_time_to_live = 5;
```

```sql
ycqlsh:example> DESCRIBE TABLE employees;
```

Following result would be shown.

```output
CREATE TABLE example.employees (
    id int,
    name text,
    job_title text,
    PRIMARY KEY (id, name)
) WITH CLUSTERING ORDER BY (name ASC)
    AND default_time_to_live = 5;
```

## See also

- [CREATE TABLE](/stable/api/ycql/ddl_create_table "CREATE TABLE")
- [DELETE](/stable/api/ycql/dml_delete/ "DELETE")
- [DROP TABLE](/stable/api/ycql/ddl_drop_table "DROP TABLE")
- [INSERT](/stable/api/ycql/dml_insert "INSERT")
- [SELECT](/stable/api/ycql/dml_select/ "SELECT")
- [UPDATE](/stable/api/ycql/dml_update/ "UPDATE")
