SQL ALTER TABLE DROP COLUMN Command
<<Previous - SQL ALTER TABLE ADD column
Next - SQL ALTER TABLE MODIFY column>>
SQL ALTER TABLE statement is used to modify or change the structure of the table. By using this ALTER TABLE, you can add, delete or modify the column of the existing table.
mysql> desc student; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | RollNo | int | YES | | NULL | | | Name | varchar(20) | YES | | NULL | | | Age | int | YES | | NULL | | | City | char(20) | YES | | NULL | | | Dept | char(10) | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 5 rows in set (0.14 sec)
The syntax to delete a column from the existing table.
ALTER TABLE table-name DROP COLUMN column-name;
Following is the example SQL query to delete the existing column [dept] from [student] table.
mysql> ALTER TABLE student DROP COLUMN Dept; Query OK, 0 rows affected (2.48 sec) Records: 0 Duplicates: 0 Warnings: 0
Now, we can check whether that column is deleted or not
mysql> desc student; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | RollNo | int | YES | | NULL | | | Name | varchar(20) | YES | | NULL | | | Age | int | YES | | NULL | | | City | char(20) | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 4 rows in set (0.00 sec)
<<Previous - SQL ALTER TABLE ADD column
Next - SQL ALTER TABLE MODIFY column>>