Skip to main content

ALTER TABLE

Modify the structure of an existing table.

Syntax

Description

ALTER TABLE modifies the structure of an existing table without requiring you to recreate the table and copy its data. Turso supports four forms of ALTER TABLE: renaming the table, renaming a column, adding a new column, and dropping an existing column.

Parameters

RENAME TO

Rename an existing table.
Renaming a table updates all references to the table in:
  • Triggers that reference the table
  • Indexes on the table
  • Foreign key constraints (both as parent and child table)
  • CHECK constraints
  • Views that reference the table
The new table name must not collide with an existing table, view, or index name in the same database.

Example

RENAME COLUMN

Rename an existing column in a table.
Renaming a column updates all references to the column in:
  • Indexes that reference the column (including expression indexes)
  • Triggers that reference the column
  • CHECK constraints that reference the column
  • Foreign key constraint definitions

Restrictions

A column rename fails if:
  • The column does not exist in the table.
  • The new column name conflicts with an existing column in the same table.
  • A trigger on the table uses a qualified reference (e.g., table_name.column_name) to the column in its body.
  • A trigger’s WHEN clause references the column.

Example

ADD COLUMN

Add a new column to an existing table. The new column is always appended as the last column.

Restrictions

A new column added with ADD COLUMN must satisfy these requirements:

Supported Column Constraints

The following constraints are supported on added columns:
  • NOT NULL (with a non-NULL default)
  • DEFAULT expression
  • CHECK (expression)
  • REFERENCES (foreign key)
  • COLLATE

Examples

Add a simple column

Add a column with a default value

Add a NOT NULL column with a default

Add a column with a foreign key

Add a column on a STRICT table

DROP COLUMN

Remove an existing column from a table.

Restrictions

A column cannot be dropped if any of the following conditions are true:

Examples

Drop a column

Verify columns after dropping

Examples

Complete Schema Evolution

See Also