To eliminate a column from table we use drop command. Suppose we have table employee with an extra field Address and we want to eliminate this.
1 2 3 4 | create table student(id int(11) NOT NULL AUTO_INCREMENT, name varchar(40), address varchar(40), PRIMARY KEY(id)); |
1 2 3 4 5 6 7 8 9 | mysql> desc student; +---------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(40) | YES | | NULL | | | address | varchar(40) | YES | | NULL | | +---------+-------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) |
To remove this column we use Drop query.
Syntax:
1 | ALTER TABLE table_name drop column_name; |
1 | ALTER TABLE student drop address; |
1 2 3 4 5 6 7 8 | mysql> desc student; +-------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(40) | YES | | NULL | | +-------+-------------+------+-----+---------+----------------+ 2 rows in set (0.00 sec) |