mysql数据表添加列_如何将列添加到MySQL表

  • Post author:
  • Post category:mysql

mysql数据表添加列

The command add column is used to add an additional column to any given MySQL table.

命令add column用于向任何给定MySQL表添加一个附加列。

To do this, you must specify the column name and type.

为此,您必须指定列名称和类型。

Note: The add column command is sometimes referred to as additional column or new column.

注意: add column命令有时称为附加列新列


如何添加MySQL列 ( How to Add a MySQL Column )

Adding a column to an existing table is done with this syntax:

使用以下语法将列添加到现有表中:

alter table

修改表

add column [new column name] [type];

添加列[新列名] [类型];

Here’s an example:

这是一个例子:

alter tableicecream add column flavor varchar (20) ; 

What this example would end up doing is adding the column “flavor” to the table “icecream,” just as it says above. It would be in the database “varchar (20)” format.

就像上面所说的,该示例最终要做的是在表“ icecream”中添加“ flavor”列。 它将采用数据库“ varchar(20)”格式。

Know, however, that the “column” clause is not required. So, you could instead use “add [new column name]…”, like this:

但是请知道,“ column”子句不是必需的。 因此,您可以改为使用“ 添加[新列名] …”,如下所示:

alter tableicecream add flavor varchar (20) ; 


在现有列之后添加列 ( Adding a Column After an Existing Column )

Something you may prefer to do is add a column after a specified existing column. So, if you’d like to add the column flavor after one called size, you could do something like this:

您可能希望做的是在指定的现有列之后添加一列。 因此,如果您想在一个称为size的后面添加列风味 ,则可以执行以下操作:

alter tableicecream add column flavor varchar (20) after size; 


更改MySQL表上的列名 ( Changing a Column Name on a MySQL Table )

You can change a column’s name with the alter table and change commands. Read more about that in the How to Change a Column Name in MySQL tutorial.

您可以使用alter tablechange命令更改列的名称。 在“ 如何在MySQL中更改列名”教程中阅读有关此内容的更多信息。

翻译自: https://www.thoughtco.com/add-column-mysql-command-2693988

mysql数据表添加列