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
- A new column needs a default if existing rows must stay valid.
- Renaming keeps the data and changes only the name.
- Dropping a column is destructive — back up first.
Keywords and builtins used here
ADDALTERCOLUMNDEFAULTDROPNOTNULLRENAMETABLETEXTTO
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.
Step 1 of 2 in Changing a schema, step 13 of 16 in Schema & constraints.