How to drop column in SQL databases?
Syntax
Here is the generic syntax to delete a column from a table in SQL:
ALTER TABLE table_name
DROP COLUMN column_name;
This syntax is pretty standard across the most popular SQL databases such as MySQL, MS SQL Server, Oracle, PostgreSQL. Even though, in some databases, you can omit the COLUMN keyword and use:
ALTER TABLE table_name
DROP column_name;
To drop multiple columns all at once:
In MS SQL Server:
ALTER TABLE table_name
DROP COLUMN column_name_1, column_name_2,...;
In PostgreSQL and MySQL:
ALTER TABLE table_name
DROP COLUMN column_name_1,
DROP COLUMN column_name_2,
...;
In Oracle:
ALTER TABLE table_name DROP (column_name_1, column_name_2);
Example
To drop the column salary
from the table company
ALTER TABLE company
DROP COLUMN salary;
Need a good GUI tool for databases? TablePlus provides a native client that allows you to access and manage Oracle, MySQL, SQL Server, PostgreSQL and many other databases simultaneously using an intuitive and powerful graphical interface.
Not on Mac? Download TablePlus for Windows.
Need a quick edit on the go? Download for iOS