Technologies Ignited

Set the auto-increment value of a table in MySQL

Advertisements

Here’s the way to set the auto-increment value of a table in MySQL:
If the table exists:

ALTER TABLE groups AUTO_INCREMENT = 1234;

Here you have to be careful, because the new value must be greater than the current one.
Else you might have problems with duplicate primary key values.

If you are creating a new table:

CREATE TABLE IF NOT EXISTS groups (
  id int(11) NOT NULL AUTO_INCREMENT,
  value int(11) NOT NULL,
  PRIMARY KEY(id)
) ENGINE = MyISAM DEFAULT CHARSET = utf8 AUTO_INCREMENT = 1234;

The last and not so bright way is just to add multiple rows until you reach the required auto-increment value and then delete them.

Advertisements

Advertisements