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 |   |       |     |

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.