suppose we have a column address in table employee.
1 2 3 4 5 | create table employee( id int(10) NOT NULL AUTO_INCREMENT, name varchar(40), department varchar(30), address varchar(50), PRIMARY KEY(id)); |
To see the description of table we use
desc employee
that will produce following result
here we can see the description of table.
1 2 3 4 5 6 7 8 9 10 | mysql> desc employee; +------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+----------------+ | id | int(10) | NO | PRI | NULL | auto_increment | | name | varchar(40) | YES | | NULL | | | department | varchar(30) | YES | | NULL | | | address | varchar(50) | YES | | NULL | | +------------+-------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec) |
if we want to eliminate the column address from employee table then we use Drop command.
Syntax:
1 | ALTER TABLE TABLE_NAME DROP COLUMN COLUMN_NAME; |
Drop query
1 | ALTER TABLE employee DROP COLUMN address; |
1 2 3 4 5 6 7 8 9 | mysql> desc employee; +------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+----------------+ | id | int(10) | NO | PRI | NULL | auto_increment | | name | varchar(40) | YES | | NULL | | | department | varchar(30) | YES | | NULL | | +------------+-------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) |
Here address is successfully removed.