Technologies Ignited

Technologies Ignited

Set the auto-increment value of a table in MySQL

leave a comment »

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.

Written by wyand

24 April 2012 at 16:56

Posted in Other

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: