SQL ALTER TABLE
Change an existing table.
Syntax
ALTER TABLE t ADD COLUMN col TYPE; ALTER TABLE t RENAME COLUMN a TO b; ALTER TABLE t RENAME TO new_name;
SQLite supports adding, renaming and dropping columns; other databases also allow changing a column's type.
Example
Query (on the shop database used in the SQL course)
ALTER TABLE products ADD COLUMN on_sale INTEGER DEFAULT 0; SELECT name, on_sale FROM products LIMIT 3;
Result
| name | on_sale |
|---|---|
| Wireless mouse | 0 |
| Mechanical keyboard | 0 |
| USB-C hub | 0 |
3 rows
Related
Learn it step by step in the free lesson Creating Tables, with exercises that check your queries.