Changing the schema
Handout
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
Changing a table's structure
A table's design is not fixed. ALTER TABLE … ADD adds a new column to an existing table:
ALTER TABLE product ADD weight DECIMAL(5, 2);
Existing rows get NULL in the new column until you fill them in.
Removing a table
DROP TABLE deletes a whole table — its structure and all its rows:
DROP TABLE product;
This cannot be undone, so use it with care. Dropping a table that other tables reference can break referential integrity.
Add a new column weight of type DECIMAL(5, 2) to the product table using ALTER TABLE.
Click Run to see the output here.
Delete the entire product table with DROP TABLE. (Afterwards only customer and orders remain.)
Click Run to see the output here.