如何使用phpmyadmin向mysql数据库中的列添加自动增量?

时间:2020-11-28 16:56:57

I've been trying to add auto-increment to one of my columns (basically an ID) but I can't find the auto-increment option for my column. Any idea where it is?

我一直在尝试将自动增量添加到我的一个列(基本上是一个ID),但我找不到我的列的自动增量选项。知道它在哪里吗?

4 个解决方案

#1


18  

You can add it like this

你可以像这样添加它

ALTER TABLE your_table
MODIFY some_column INT NOT NULL AUTO_INCREMENT;

#2


15  

To use the GUI:

要使用GUI:

Click the STRUCTURE tab to see the list of existing fields

单击STRUCTURE选项卡以查看现有字段列表

To set a field as the PRIMARY FIELD, click the gold key -- it will turn silver.

要将字段设置为PRIMARY FIELD,请单击金键 - 它将变为银色。

To set a field (usually the same field) as auto-increment:
a. Click CHANGE for that field
b. Look to the far right and checkmark the AI box
c. Click SAVE button

要设置一个字段(通常是相同的字段)作为自动增量:a。单击该字段的CHANGE b。向右边看,勾选AI框c。单击“保存”按钮

#3


5  

A couple quick points based on recent experience:

根据最近的经验,几个快速点:

  1. To the original question, how to select auto-increment with phpmyadmin, it's the small AI check box on the change screen for a field name.

    对于原始问题,如何使用phpmyadmin选择自动增量,它是更改屏幕上字段名称的小AI复选框。

  2. When I tried the "ALTER TABLE tablew_name CHANGE id id BIGINT(20) NOT NULL AUTO_INCREMENT;" solution above, phpmyadmin gave me an error message saying the field had to have a key. I selected a Unique key and the error message went away and the field now auto increments.

    当我尝试“ALTER TABLE tablew_name CHANGE id id BIGINT(20)NOT NULL AUTO_INCREMENT;”上面的解决方案,phpmyadmin给了我一个错误消息,说该字段必须有一个键。我选择了一个唯一键,错误消息消失了,现在该字段自动递增。

#4


4  

This wont work if there are any foreign keys defined, and that is very likely for id fields.

如果定义了任何外键,这将不起作用,这很可能是id字段。

use:

使用:

ALTER TABLE tablew_name CHANGE id id BIGINT(20) NOT NULL AUTO_INCREMENT;

instead

代替

#1


18  

You can add it like this

你可以像这样添加它

ALTER TABLE your_table
MODIFY some_column INT NOT NULL AUTO_INCREMENT;

#2


15  

To use the GUI:

要使用GUI:

Click the STRUCTURE tab to see the list of existing fields

单击STRUCTURE选项卡以查看现有字段列表

To set a field as the PRIMARY FIELD, click the gold key -- it will turn silver.

要将字段设置为PRIMARY FIELD,请单击金键 - 它将变为银色。

To set a field (usually the same field) as auto-increment:
a. Click CHANGE for that field
b. Look to the far right and checkmark the AI box
c. Click SAVE button

要设置一个字段(通常是相同的字段)作为自动增量:a。单击该字段的CHANGE b。向右边看,勾选AI框c。单击“保存”按钮

#3


5  

A couple quick points based on recent experience:

根据最近的经验,几个快速点:

  1. To the original question, how to select auto-increment with phpmyadmin, it's the small AI check box on the change screen for a field name.

    对于原始问题,如何使用phpmyadmin选择自动增量,它是更改屏幕上字段名称的小AI复选框。

  2. When I tried the "ALTER TABLE tablew_name CHANGE id id BIGINT(20) NOT NULL AUTO_INCREMENT;" solution above, phpmyadmin gave me an error message saying the field had to have a key. I selected a Unique key and the error message went away and the field now auto increments.

    当我尝试“ALTER TABLE tablew_name CHANGE id id BIGINT(20)NOT NULL AUTO_INCREMENT;”上面的解决方案,phpmyadmin给了我一个错误消息,说该字段必须有一个键。我选择了一个唯一键,错误消息消失了,现在该字段自动递增。

#4


4  

This wont work if there are any foreign keys defined, and that is very likely for id fields.

如果定义了任何外键,这将不起作用,这很可能是id字段。

use:

使用:

ALTER TABLE tablew_name CHANGE id id BIGINT(20) NOT NULL AUTO_INCREMENT;

instead

代替