本文翻譯自: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
? 如何刪除列IsDeleted
?
#1樓
參考:https://stackoom.com/question/wbqI/如何從MySQL中的表中刪除列
#2樓
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
. 請注意, COLUMN
關鍵字是可選的,因爲MySQL只接受DROP IsDeleted
。 Also, to drop multiple columns, you have to separate them by commas and include the DROP
for each one. 另外,要刪除多個列,必須用逗號分隔它們,併爲每個列包含DROP
。
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. 這允許您在一個語句中的同一個表上DROP
, ADD
和ALTER
多個列。 From the MySQL reference manual : 從MySQL參考手冊 :
You can issue multiple
ADD
,ALTER
,DROP
, andCHANGE
clauses in a singleALTER TABLE
statement, separated by commas. 您可以在單個ALTER TABLE
語句中發出多個ADD
,ALTER
,DROP
和CHANGE
子句,以逗號分隔。 This is a MySQL extension to standard SQL, which permits only one of each clause perALTER TABLE
statement. 這是標準SQL的MySQL擴展,它只允許每個ALTER TABLE
語句中的一個子句。
#3樓
要刪除列,請使用此項,
ALTER TABLE `tbl_Country` DROP `your_col`
#4樓
ALTER TABLE tbl_Country DROP columnName;
#5樓
使用ALTER
:
ALTER TABLE `tbl_Country` DROP COLUMN `column_name`;
#6樓
ALTER TABLE `tablename` DROP `columnname`;
要麼,
ALTER TABLE `tablename` DROP COLUMN `columnname`;