如何在MySQL中设置初始值和自动递增? [英] How to set initial value and auto increment in MySQL?

查看:88
本文介绍了如何在MySQL中设置初始值和自动递增?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为MySQL表中从1001开始的"id"列设置初始值?

How do I set the initial value for an "id" column in a MySQL table that start from 1001?

我想插入"INSERT INTO users (name, email) VALUES ('{$name}', '{$email}')";

未指定id列的初始值.

Without specifying the initial value for the id column.

推荐答案

使用此:

ALTER TABLE users AUTO_INCREMENT=1001;

或者如果您还没有添加ID列,还可以添加它

or if you haven't already added an id column, also add it

ALTER TABLE users ADD id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    ADD INDEX (id);

这篇关于如何在MySQL中设置初始值和自动递增?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆