[英]How to set an AUTO_INCREMENT field with to start with the value 6000 in mysql?
如何在mysql中没有自动增量键设置字段自动增量或如何在mysql中设置字段自动增量为起始值6000?
... how set a field auto increment with start value 6000 in mysql? ...如何在mysql中使用起始值6000设置字段自动增量?
If your table already exists: 如果您的表已存在:
ALTER TABLE your_table AUTO_INCREMENT = 6000;
If you are creating your table from scratch: 如果您从头开始创建表:
CREATE TABLE your_table () AUTO_INCREMENT = 6000;
Source and further reading: 来源和进一步阅读:
Test case: 测试用例:
CREATE TABLE users (
user_id int NOT NULL,
name varchar(50),
PRIMARY KEY (user_id)
);
INSERT INTO users VALUES (1, 'Bob');
INSERT INTO users VALUES (2, 'Joe');
INSERT INTO users VALUES (3, 'Paul');
ALTER TABLE users MODIFY user_id int NOT NULL AUTO_INCREMENT;
ALTER TABLE users AUTO_INCREMENT = 6000;
INSERT INTO users (name) VALUES ('Keith');
INSERT INTO users (name) VALUES ('Steve');
INSERT INTO users (name) VALUES ('Jack');
SELECT * FROM users;
+---------+-------+
| user_id | name |
+---------+-------+
| 1 | Bob |
| 2 | Joe |
| 3 | Paul |
| 6000 | Keith |
| 6001 | Steve |
| 6002 | Jack |
+---------+-------+
6 rows in set (0.01 sec)
ALTER TABLE tbl_name AUTO_INCREMENT = 6000
但请注意,此表中应该没有PK lager 6000!
mysql将为您显示正确的语法,如果对包含自动增量PK和某些数据的表执行以下操作,则会更多:
SHOW CREATE TABLE your_tablename;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.