How do I set auto increment starting at 5000
Let's say I have 67,828 records in my current database without Primary Key & AUTO_INCREMENT
Now I want add one column name ID
a开发者_运维百科s primary key, AUTO_INCREMENT and starting with number 5000
.
Current DB
Name Email
--------------------
John john@doe.com
Peter peter@john.com
New format should be
ID Name Email
--------------------
5000 John john@doe.com
5001 Peter peter@john.com
Let me know.
Try this one -
ALTER TABLE table_name
ADD COLUMN id INT(11) NOT NULL AUTO_INCREMENT FIRST,
ADD PRIMARY KEY (id),
AUTO_INCREMENT = 5000;
To start with an AUTO_INCREMENT value other than 1, you can set that value with CREATE TABLE or ALTER TABLE, like this:
ALTER TABLE tbl AUTO_INCREMENT = 5000;
http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
ALTER TABLE tbl AUTO_INCREMENT = 5000
Please use this query for MySQL
ALTER TABLE table_name AUTO_INCREMENT =2000
If I recall correctly, the SQL to do this is something like
ALTER TABLE table ADD ID INT UNSIGNED AUTO_INCREMENT, ADD INDEX (ID);
ALTER TABLE table AUTO_INCREMENT = 5000;
精彩评论