Author Archives: Jagjit

Drop a column from the table in MySQL \ MariaDB

Drop a column from the table in MySQL \ MariaDB

Alter command is used to drop the column from the table in MySQL \ MariaDB.

Syntax:

ALTER TABLE table_name
  DROP COLUMN column_name;

Example:

DESC EMP;
Field         |Type        |Null|Key|Default|Extra|
--------------+------------+----+---+-------+-----+
employeeNumber|int(11)     |NO  |PRI|       |     |
lastName      |varchar(50) |NO  |   |       |     |
firstName     |varchar(50) |NO  |   |       |     |
extension     |varchar(10) |NO  |   |       |     |
email         |varchar(100)|NO  |   |       |     |
officecode    |varchar(200)|YES |MUL|       |     |
reportsTo     |int(11)     |YES |MUL|       |     |
jobTitle      |varchar(50) |NO  |   |       |     |

--Drop the column jobtitile from the table:


alter table emp drop column jobtitle;


--Check the table again:
desc emp;
Field         |Type        |Null|Key|Default|Extra|
--------------+------------+----+---+-------+-----+
employeeNumber|int(11)     |NO  |   |       |     |
lastName      |varchar(50) |NO  |   |       |     |
firstName     |varchar(50) |NO  |   |       |     |
extension     |varchar(10) |NO  |   |       |     |
email         |varchar(100)|NO  |   |       |     |
officecode_new|varchar(200)|YES |   |       |     |
reportsTo     |int(11)     |YES |   |       |     |