This tutorial will help you learn how to remove a column from a database table using Standard SQL.
SQL Drop Column
In Standard SQL, you can manually remove a column from a table using the ALTER TABLE DROP COLUMN statement.
This DDL statement will attempt to delete the specified column from the table.
The syntax for dropping a column in Standard SQL is shown below:
DROP COLUMN "column_name";
Take the example table below:
We can remove the active column as shown in the following query:
Remember that the command will fail if foreign key constraints reference the column.
In some database engines, the statement to remove a column may vary. For example, the syntax above is supported by Standard SQL and database engines, such as Oracle, SQL Server, and PostgreSQL.
However, the command varies slightly in MySQL. The syntax is shown below:
DROP "column_name";
In this case, we do not need to specify DROP COLUMN although supported. Example usage is shown below:
ALTER TABLE customer DROP active;
Conclusion
This short article discusses how to delete a column from a database table using Standard SQL and MySQL variants. We hope you found this article helpful. Check the other Linux Hint articles for more tips and tutorials.