---
title: Columns
description: Add, remove, rename, and change the type of a table's columns.
sidebar:
  order: 3
---

A table's columns are not fixed once it exists. You can add new ones, rename
them, change their type, and remove them — in both simple and advanced mode.
The examples below use the [example library](/getting-started/example-library/);
to see a table's current columns at any time, use `show table`:

```rdbms
show table books
```

```
books
┌───────────┬────────┬─────────────┐
│ Name      │ Type   │ Constraints │
├───────────┼────────┼─────────────┤
│ book_id   │ serial │ PK          │
│ title     │ text   │ NOT NULL    │
│ author_id │ int    │             │
│ published │ int    │             │
│ isbn      │ text   │ UNIQUE      │
└───────────┴────────┴─────────────┘
```

## Add a column

```rdbms
add column to books: page_count (int)
```

The new column goes at the end of the table and is empty for existing rows.
After the change, the updated structure is shown automatically. If you add a
`serial` or `shortid` column — or change a column *to* one of those types —
the empty cells are filled with freshly generated values in the same step (see
[Types](/reference/types/)). To fill the new column on existing rows with
generated data, use
[`seed books.page_count`](/reference/generating-sample-data/#filling-one-column).

## Rename a column

```rdbms
rename column in books: page_count to pages
```

## Change a column's type

```rdbms
change column in books: pages (text)
```

Changing a type re-interprets every existing value. When the conversion could
lose information — turning `text` into `int`, say, where some rows do not look
like numbers — the playground refuses by default and shows you exactly which
rows are the problem, so nothing is silently corrupted. Two flags let you
decide what should happen instead:

- `--force-conversion` — go ahead and convert, accepting the loss.
- `--dont-convert` — keep the column's stored values as they are under the new
  type.

A primary-key column, or a column taking part in a
[relationship](/reference/relationships/), is protected — remove the
relationship first if you need to restructure it.

## Drop a column

```rdbms
drop column from books: pages
```

If the column is covered by an [index](/reference/indexes/), the drop is
refused so you do not lose the index by surprise. Add `--cascade` to drop the
column and the index that covers it together:

```rdbms
drop column from books: pages --cascade
```

## In advanced mode

The same operations are written as standard `ALTER TABLE` statements:

```sql
alter table books add column page_count int
alter table books rename column page_count to pages
alter table books alter column pages type text
alter table books drop column pages
```

## Syntax

```rdbms-syntax
add column [to] [table] <Table>: <Name> (<Type>)
rename column [in] [table] <Table>: <Old> to <New>
change column [in] [table] <Table>: <Name> (<Type>) [--force-conversion | --dont-convert]
drop column [from] [table] <Table>: <Name> [--cascade]
```

See also [Types](/reference/types/), [Constraints](/reference/constraints/),
and [Tables](/reference/tables/).
