php 如何在 PHPMyAdmin 中使 MySql 中的字段自动递增?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/434810/
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 do I make a field in MySql auto-incrementing in PHPMyAdmin?
提问by chustar
I created a field in my table and set it as the index but I can't get it to increase on it s own when a new item is added. How do I do make it do this through PHPMyAdmin?
我在表中创建了一个字段并将其设置为索引,但是当添加新项目时,我无法让它自行增加。我如何通过 PHPMyAdmin 做到这一点?
回答by Brian Fisher
Select the A_I check box when creating/editing a column.
创建/编辑列时选中 A_I 复选框。
回答by E. Verdi
The Answer of Brian Fisher is correct, but there is another way if you want to try it in code. Just Click on the database, go to SQL and type for example the following code:
Brian Fisher 的答案是正确的,但如果您想在代码中尝试,还有另一种方法。只需单击数据库,转到 SQL 并键入例如以下代码:
CREATE TABLE Player (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
username CHAR(30) NOT NULL,
PRIMARY KEY (id)
)
CREATE TABLE Player (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
username CHAR(30) NOT NULL,
PRIMARY KEY (id)
)
Explanation:
MEDIUMINT:
INT with minimum Value -8388608 and maxmimum Value 8388607
or minimum Value 0 and maxmimum Value 16777215
说明:
MEDIUMINT:
INT 最小值为 -8388608 和最大值 8388607
或最小值 0 和最大值 16777215
NOT NULL (Two operators in one):
This value may never be empty
NOT NULL(两个运算符合二为一):
此值可能永远不会为空
AUTO_INCREMENT:
What you where looking for
The AUTO_INCREMENT attribute can be used to generate a unique identity for new rows.
AUTO_INCREMENT:
您要查找
的内容 AUTO_INCREMENT 属性可用于为新行生成唯一标识。

