Lessons › SQL › Chapter 7: Creating and changing tables
SQL lesson
ALTER TABLE
ALTER TABLE changes a table's shape, not its rows. ADD COLUMN puts a new, empty column on every row. RENAME COLUMN gives a column a clearer name. To fill a new column, use UPDATE from Level 49.
Try this lesson free →Example
Add or rename a column
ALTER TABLE targets ADD COLUMN region TEXT| store | month | target | region |
|---|---|---|---|
| Lagos | 2024-03-01 | 5000 | |
| Accra | 2024-03-01 | 3000 |
Step by step
- The table whose shape changes.
ALTER TABLE targets ADD COLUMN region TEXT - A new, empty column on every row.
ALTER TABLE targets ADD COLUMN region TEXT - Same data, clearer name.
ALTER TABLE targets ADD COLUMN region TEXT
Practice
1. Add a column called region (TEXT) to targets.
ALTER TABLE targets ADD COLUMN region TEXT2. In targets, rename the column target to monthly_target.
ALTER TABLE targets RENAME COLUMN target TO monthly_target3. Add a column called reason (TEXT) to returns.
ALTER TABLE returns ADD COLUMN reason TEXT4. Add a column called discount (NUMERIC) to orders.
ALTER TABLE orders ADD COLUMN discount NUMERIC5. In staff, rename the column name to full_name.
ALTER TABLE staff RENAME COLUMN name TO full_nameLearn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →