How to delete a column from a table in MySQL

2019-01-29 15:13发布

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?

12条回答
我命由我不由天
2楼-- · 2019-01-29 15:38

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;
查看更多
三岁会撩人
3楼-- · 2019-01-29 15:41
ALTER TABLE tbl_Country DROP columnName;
查看更多
贼婆χ
4楼-- · 2019-01-29 15:44

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;
查看更多
唯我独甜
5楼-- · 2019-01-29 15:47

You can use

alter table <tblname> drop column <colname>
查看更多
放荡不羁爱自由
6楼-- · 2019-01-29 15:48

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;
查看更多
▲ chillily
7楼-- · 2019-01-29 15:49

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;
查看更多
登录 后发表回答