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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19434801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:09:39  来源:igfitidea点击:

How to add auto-increment to column in mysql database using phpmyadmin?

mysqldatabasephpmyadmin

提问by SKLAK

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)添加自动增量,但我找不到我的列的自动增量选项。知道它在哪里吗?

回答by juergen d

You can add it like this

你可以这样添加

ALTER TABLE your_table
MODIFY some_column INT NOT NULL AUTO_INCREMENT;

回答by cssyphus

To use the GUI:

要使用 GUI:

Click the STRUCTUREtab 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 CHANGEfor that field
b. Look to the far right and checkmark the AIbox
c. Click SAVEbutton

要设置字段(通常是相同的字段)作为自动递增:
一。单击CHANGE该字段
b。查看最右侧并选中AI
c。单击SAVE按钮

回答by FredHead

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.

  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.

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

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

回答by Oliver

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

反而

回答by Miguel Jumping

The SQL script is correct

SQL 脚本是正确的

ALTER TABLE your_table MODIFY some_column INT NOT NULL AUTO_INCREMENT;

but if you try so make before in the visual mode, with the mysql version 4.7.4, in the struct of the table

但是如果你之前在可视模式下尝试过,使用mysql版本4.7.4,在表的结构中

Appear when you create the table one option to say "A_I" , if you put your mouse appear message with AUTO_INCREMENT (The version of the foto is in Spanish version)

当你创建表格时出现一个选项说“A_I”,如果你把鼠标放在 AUTO_INCREMENT 出现消息(照片的版本是西班牙语版本)