如何從MySQL中的表中刪除列

本文翻譯自: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. 這允許您在一個語句中的同一個表上DROPADDALTER多個列。 From the MySQL reference manual : MySQL參考手冊

You can issue multiple ADD , ALTER , DROP , and CHANGE clauses in a single ALTER TABLE statement, separated by commas. 您可以在單個ALTER TABLE語句中發出多個ADDALTERDROPCHANGE子句,以逗號分隔。 This is a MySQL extension to standard SQL, which permits only one of each clause per ALTER 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`;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章