Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a column from a table in MySQL

Given the table created using:

CREATE TABLE tbl_Country (   CountryId INT NOT NULL AUTO_INCREMENT,   IsDeleted bit,   PRIMARY KEY (CountryId)  ) 

How can I delete the column IsDeleted?

like image 545
raji Avatar asked Dec 20 '12 09:12

raji


People also ask

How do I delete a column in MySQL workbench?

Delete Selected Columns: Select multiple contiguous columns by right-clicking and pressing the Shift key. Use the Control key to select separated columns. Refresh: Update all information in the Columns subtab. Clear Default: Clear the assigned default value.


1 Answers

ALTER TABLE tbl_Country DROP COLUMN IsDeleted; 

Here's a working example.

Note that the COLUMN keyword is optional, as MySQL will accept just DROP IsDeleted. Also, to drop multiple columns, you have to separate them by commas and include the DROP for each one.

ALTER TABLE tbl_Country   DROP COLUMN IsDeleted,   DROP COLUMN CountryName; 

This allows you to DROP, ADD and ALTER multiple columns on the same table in the one statement. From the MySQL reference manual:

You can issue multiple ADD, ALTER, DROP, and CHANGE clauses in a single ALTER TABLE statement, separated by commas. This is a MySQL extension to standard SQL, which permits only one of each clause per ALTER TABLE statement.

like image 89
Cynical Avatar answered Sep 21 '22 11:09

Cynical