MySQL 如何使主键从 1000 开始?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2130635/
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 make a primary key start from 1000?
提问by user198729
create table tablename (
id integer unsigned not null AUTO_INCREMENT,
....
primary key id
);
I need the primary key to start from 1000.
我需要主键从 1000 开始。
I'm using MySQL.
我正在使用 MySQL。
回答by davidosomething
If your table has already been created with an auto-increment. so you can use
如果您的表已经使用自动增量创建。所以你可以使用
ALTER TABLE tbl AUTO_INCREMENT = 1000;
otherwise put the AUTO_INCREMENT = 1000;
in your CREATE TABLE
否则把AUTO_INCREMENT = 1000;
你的CREATE TABLE
it goes before the final );
它在决赛之前);
回答by zombat
You can use ALTER TABLE to accomplish this:
您可以使用 ALTER TABLE 来完成此操作:
ALTER TABLE tablename AUTO_INCREMENT = 1000;
If you want it as part of the CREATE TABLE
statement, just put it after the table definition:
如果您希望将其作为CREATE TABLE
语句的一部分,只需将其放在表定义之后:
CREATE TABLE tablename (
...
) ENGINE=InnoDB AUTO_INCREMENT=1000;
回答by Chris C
ALTER TABLE yourtable AUTO_INCREMENT = 1000
回答by Sarfraz
Well in such a situation, i simply open up my mysql client software and i type 1000, etc right in the primary key field. The record getting inserted will have ids greater than 1000 now.
那么在这种情况下,我只需打开我的 mysql 客户端软件,然后在主键字段中输入 1000 等即可。现在插入的记录的 ID 将大于 1000。