BBampaa

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 →
About 5–10 minutes · no sign-up needed

Example

Changing a Retail Table Structure with ALTER TABLE

ALTER TABLE products ADD COLUMN stock_count INTEGER

Result:

Step by step

  1. Start with ALTER TABLE and the name of the table you want to modify.
    ALTER TABLE products;
  2. ADD COLUMN, DROP COLUMN, RENAME COLUMN, or ALTER COLUMN - pick what you need.
    ALTER TABLE products
      ADD COLUMN stock_count INTEGER;
  3. Run a quick SELECT to confirm the new column shape is what you expected.
    SELECT *
    FROM products
    LIMIT 1;

Practice

Try each one in your head first, then open the answer.

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 BOOLEAN
2. 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 BOOLEAN
3. 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 TEXT
4. 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 TEXT
5. 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 BOOLEAN

Learn 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 →
About 5–10 minutes · no sign-up needed