How to delete a column from a table in MySQL

和自甴很熟 提交于 2019-11-29 19:02:39
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.

Saharsh Shah

Use ALTER TABLE with DROP COLUMN to drop a column from a table, and CHANGE or MODIFY to change a column.

ALTER TABLE tbl_Country DROP COLUMN IsDeleted;
ALTER TABLE tbl_Country MODIFY IsDeleted tinyint(1) NOT NULL;
ALTER TABLE tbl_Country CHANGE IsDeleted IsDeleted tinyint(1) NOT NULL;
Arman

To delete a single column from a table you can use this:

ALTER TABLE table_name DROP COLUMN Column_name;

To delete multiple columns, do this:

ALTER TABLE table_name DROP COLUMN Column_name, DROP COLUMN Column_name;

To delete columns from table.

ALTER TABLE tbl_Country DROP COLUMN IsDeleted1, DROP COLUMN IsDeleted2;

Or without word 'COLUMN'

ALTER TABLE tbl_Country DROP IsDeleted1, DROP IsDeleted2;
echo_Me

To delete column use this,

ALTER TABLE `tbl_Country` DROP `your_col`
Kapil gopinath

You can use

alter table <tblname> drop column <colname>
Avinash Nair
ALTER TABLE `tablename` DROP `columnname`;

Or,

ALTER TABLE `tablename` DROP COLUMN `columnname`;
Lo Juego

Use ALTER:

ALTER TABLE `tbl_Country` DROP COLUMN `column_name`;
Sterling Archer
ALTER TABLE tbl_Country DROP columnName;
ALTER TABLE `tbl_Country` DROP `IsDeleted`;

If you are running MySQL 5.6 onwards, you can make this operation online, allowing other sessions to read and write to your table while the operation is been performed:

ALTER TABLE tbl_Country DROP COLUMN IsDeleted, ALGORITHM=INPLACE, LOCK=NONE;
ALTER TABLE table_name DROP COLUMN column_name

When we perform an operation like deleting a column from the table it changes the structure of your table. For performing such kind of operation we need to use Data Definition Language (DDL) statements. In this case we have to use ALTER statement.

ALTER - alters the structure of the database

The query would be -

alter table tbl_Country drop column IsDeleted;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!