48
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.

user198729
  • 58,910
  • 106
  • 245
  • 345

4 Answers4

85

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 );

Priya Jayapal
  • 243
  • 3
  • 8
davidosomething
  • 3,279
  • 1
  • 25
  • 33
39

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;
zombat
  • 90,260
  • 24
  • 155
  • 163
7
ALTER TABLE yourtable AUTO_INCREMENT = 1000
Chris C
  • 1,973
  • 14
  • 18
-4

Well in such a situation, i simply open up my mysql client software and i type 1000, etc right in the primary key field. The record getting inserted will have ids greater than 1000 now.

Sarfraz
  • 367,681
  • 72
  • 526
  • 573