How to make a primary key start from 1000?

create table tablename (
    id integer unsigned not null AUTO_INCREMENT,
    ....
    primary key id
);

I need the primary key to start from 1000.

I'm using MySQL.


Solution 1:

If your table has already been created with an auto-increment. so you can use

ALTER TABLE tbl AUTO_INCREMENT = 1000;

otherwise put the AUTO_INCREMENT = 1000; in your CREATE TABLE

it goes before the final );

Solution 2:

You can use ALTER TABLE to accomplish this:

ALTER TABLE tablename AUTO_INCREMENT = 1000;

If you want it as part of the CREATE TABLE statement, just put it after the table definition:

CREATE TABLE tablename (
  ...
) ENGINE=InnoDB AUTO_INCREMENT=1000;

Solution 3:

ALTER TABLE yourtable AUTO_INCREMENT = 1000