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
How to add auto-increment to column in mysql database using phpmyadmin?
提问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 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
要设置字段(通常是相同的字段)作为自动递增:
一。单击CHANGE
该字段
b。查看最右侧并选中AI
框
c。单击SAVE
按钮
回答by FredHead
A couple quick points based on recent experience:
根据最近的经验总结几点:
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.
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.
对于原始问题,如何使用 phpmyadmin 选择自动增量,它是字段名称更改屏幕上的小 AI 复选框。
当我尝试“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,在表的结构中
当你创建表格时出现一个选项说“A_I”,如果你把鼠标放在 AUTO_INCREMENT 出现消息(照片的版本是西班牙语版本)