开发者

Error when use auto_increment in MySQL

开发者 https://www.devze.com 2023-02-23 05:09 出处:网络
I meet some errors when using auto_increment in MySQL. code is here: user_id bigint(20) unsigned not null auto_increment=1000

I meet some errors when using auto_increment in MySQL.

code is here:

user_id bigint(20) unsigned not null auto_increment=1000

but when I try

user_id bigint(20) unsigned not null au开发者_如何学编程to_increment

it works. why?


This should work:


create table test1 (
id int unsigned not null auto_increment,
primary key (id)
)auto_increment=100;


Are you trying to seed the auto increment number?

If so, the syntax is part of the CREATE|ALTER TABLE command.

See http://dev.mysql.com/doc/refman/5.5/en/example-auto-increment.html


This happens because auto increment is set for the table and not a particular column. So to start from 1000, Create a table column with just auto_increment

And then alter the table using

ALTER TABLE your_table_name AUTO_INCREMENT=1000;


auto increment of mysql is only +1 value.

look at this http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html

0

精彩评论

暂无评论...
验证码 换一张
取 消