Changing the schema
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.
Common mistakes
ALTER TABLEadds or changes a column.- Existing rows get NULL in a new column unless you set a default.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Add a new column weight of type DECIMAL(5, 2) to the product table using ALTER TABLE.
Click Run to see the output here.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Delete the entire product table with DROP TABLE. (Afterwards only customer and orders remain.)
Click Run to see the output here.