typestar

ALTER TABLE in SQL

Schema changes after the fact: add, rename and drop columns.

ALTER TABLE users
ADD COLUMN timezone TEXT NOT NULL DEFAULT 'UTC';

ALTER TABLE users
RENAME COLUMN signup_date TO created_at;

ALTER TABLE users
DROP COLUMN legacy_id;

How it works

  1. A new column needs a default if existing rows must stay valid.
  2. Renaming keeps the data and changes only the name.
  3. Dropping a column is destructive — back up first.

Keywords and builtins used here

The run, in numbers

Lines
8
Characters to type
168
Tokens
28
Three-star pace
95 tpm

At the three-star pace of 95 tokens a minute, this run takes about 18 seconds.

Type this snippet

Step 1 of 2 in Changing a schema, step 13 of 16 in Schema & constraints.

← Previous Next →