MySQL – Delete Column

We can delete a column from MySQL Table using ALTER command.

In this tutorial, we shall delete or drop a column from a table using MySQL DROP COLUMN statement.

Syntax – Delete Column

The syntax of MySQL DROP COLUMN is:

  ALTER TABLE table_name
  DROP COLUMN column_name;

where

  • table_name is the name of the table from which we are going to delete the column
  • column_name is the name of the column that we shall delete

Example 1 – Drop a Column from MySQL Table

Consider the following table students.

MySQL Table data with newly added column

To delete the column id from students table, run the following SQL Query:

</>
Copy
ALTER TABLE students
DELETE COLUMN id;
MySQL DROP COLUMN from TABLE

The result of the Query states that the execution is successful and 2 rows got effected.

Let us see the contents of students table.

MySQL Table after deleting Column

Effects of deleting a column in MySQL Table

MySQL deals with Relational Databases. Schema of a table can be dependent on the columns of other tables. When you delete a column in a table, all the elements in the Database that are dependent on the deleted column get affected.

Effect of deleting a column on Triggers

There could be Triggers which operate on the columns of the tables.

Effect of deleting a column on Stored Procedures

There could be Stored Procedures which may be dependent on the column that is deleted.

Conclusion

Before deleting a column of MySQL Table, know the consequences on related Triggers and Stored Procedures and other tables and perform the action with caution.

In this MySQL Tutorial, we have learnt how to delete column of MySQL table and the effects of doing so on other elements of the database.