How can I set a non-auto-increment field to auto increment in MySQL? And how can I set the auto increment start value to 6000?
Asked
Active
Viewed 4.3k times
3 Answers
20
... how set a field auto increment with start value 6000 in mysql?
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)

Daniel Vassallo
- 337,827
- 72
- 505
- 443
-
1Great, Can we set more than one column as auto_increment in mysql or any other way to do this.. Thanks – Ajay Aug 27 '10 at 20:17
-
@DanielBrunner, Try it. Insert some rows and check their values. Does it work? – Pacerier Feb 03 '15 at 15:09
2
ALTER TABLE tbl_name AUTO_INCREMENT = 6000
but be aware you should have no PK lager 6000 in this table !

Rufinus
- 29,200
- 6
- 68
- 84
-
Great, Can we set more than one column as auto_increment in mysql or any other way to do this.. Thanks – Ajay Aug 27 '10 at 20:17