2

Possible Duplicate:
MySQL: Reorder/Reset auto increment primary key?

I have an auto increment field in my sql, by accident i deleted something now my tables are off because the auto increment number jumped. I forgot the exact sql command but i remember there was an Select table set auto increment='whatever' i just forgot the syntax, can anyone help?

Community
  • 1
  • 1
Dnaso
  • 1,335
  • 4
  • 22
  • 48
  • What does "off" mean - is there just a gap? – Michael Nov 12 '12 at 20:39
  • I am getting the vibe from your question that it is significant the auto increment is in order. If so, why? – Malkus Nov 12 '12 at 20:39
  • because when i made my database i was stupid enough to do it that way =( in the mean time i need to fix the issue before i redo my schema – Dnaso Nov 12 '12 at 20:45
  • It happens to the best of us, we are all learning. I would recommend doing a dump of the database and testing any commands against a local instance to avoid further corruption. – Malkus Nov 12 '12 at 20:48
  • yeah i mean i was NEW NEW to programming and my db is now huge so like to do it over again is BLAH one of those things, ill get around to it though eventually, and i think i should maybe start on a fresh server so i dont patch up crap – Dnaso Nov 12 '12 at 20:51

4 Answers4

7
ALTER TABLE theTableInQuestion AUTO_INCREMENT=1234  
Malkus
  • 3,686
  • 2
  • 24
  • 39
4
ALTER TABLE YOUR_TABLE AUTO_INCREMENT=YOUR_DESIRED_NUMBER;
Marc
  • 16,170
  • 20
  • 76
  • 119
m4t1t0
  • 5,669
  • 3
  • 22
  • 30
1

See Below:

ALTER TABLE tbl AUTO_INCREMENT = newNumber;
Malkus
  • 3,686
  • 2
  • 24
  • 39
Matt Clark
  • 27,671
  • 19
  • 68
  • 123
1

According to the manual:

ALTER table drop column autoinc_column;
ALTER table add column autoinc_column ...;

Where "..." is the same parameters used to create the initial column.

hd1
  • 33,938
  • 5
  • 80
  • 91