Lessons › SQL › Deep Dive: Database Admin & ETL
SQL lesson
ALTER TABLE
ALTER TABLE reshapes an existing table's structure - adding new columns, renaming old ones, or dropping ones you no longer need - without touching the data already stored in it. Like remodeling a filing cabinet by adding a new drawer while all the folders inside stay exactly where they were.
Try this lesson free →Example
Changing a Retail Table Structure with ALTER TABLE
ALTER TABLE products ADD COLUMN stock_count INTEGERStep by step
- Start with ALTER TABLE and the name of the table you want to modify.
ALTER TABLE products; - ADD COLUMN, DROP COLUMN, RENAME COLUMN, or ALTER COLUMN - pick what you need.
ALTER TABLE products ADD COLUMN stock_count INTEGER; - Run a quick SELECT to confirm the new column shape is what you expected.
SELECT * FROM products LIMIT 1;
Practice
1. Write an ALTER TABLE statement to add a new column called is_active of type BOOLEAN to the products table.
ALTER TABLE products ADD COLUMN is_active BOOLEAN2. Write an ALTER TABLE statement to add a new column called is_active of type BOOLEAN to the customers table.
ALTER TABLE customers ADD COLUMN is_active BOOLEAN3. Write an ALTER TABLE statement to add a new column called notes of type TEXT to the orders table.
ALTER TABLE orders ADD COLUMN notes TEXT4. Write an ALTER TABLE statement to add a new column called status of type TEXT to the inventory table.
ALTER TABLE inventory ADD COLUMN status TEXT5. Write an ALTER TABLE statement to add a new column called is_active of type BOOLEAN to the suppliers table.
ALTER TABLE suppliers ADD COLUMN is_active BOOLEANLearn 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 →