Dropping a column
- SQL course
- Intermediate
- Lesson 108/115
- 4 min
Remove a column with DROP COLUMN.
Dropping a column
With DROP COLUMN you remove a column from a table. The column data is deleted.
ALTER TABLE products
DROP COLUMN stock;This query removes the stock column.
Dropping a column — details
DROP COLUMN cannot be undone. All data in the column is lost. Backup before using it.
For example, ALTER TABLE customers DROP COLUMN fax permanently deletes every stored fax number.
Practice Dropping a column
Drop the stock column from products.
Starter code
-- drop column
ALTER TABLE productsSample solution
ALTER TABLE products
DROP COLUMN stock;Expected output
Tablo güncellendi
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Dropping a column: match the terms
| Term | Meaning |
|---|---|
DROP COLUMN |
drop column |
data |
lost |
cannot undo |
permanent |
backup |
first |
2 Add DROP COLUMN
ALTER TABLE products
____ stock;
ALTER TABLE products
DROP COLUMN stock;
Explanation: DROP COLUMN is the right answer.
3 What does DROP COLUMN do to data?
- Keeps it
- Moves it
- Deletes them Correct answer
- Hides it
Explanation: DROP COLUMN deletes data.