Jump to content


Photo

Update auto_increment Column


  • Please log in to reply
5 replies to this topic

#1 pootlecat

pootlecat
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 09 October 2006 - 04:30 PM

I have a table where the auto_increment column starts at 1237333 and I want to change it so that it starts at 1 instead. Is there an easy way to do this at all?
Thanks for any help you can give me!

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 10 October 2006 - 03:27 PM

ALTER TABLE yourTABLE AUTO_INCREMENT = N
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 pootlecat

pootlecat
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 10 October 2006 - 05:17 PM

I just noticed your reply to me - thanks!
So doign this command will update every row in the table?

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 10 October 2006 - 07:23 PM

I don't know what you mean by that... it won't update anything.  But it will reset the internal table counter.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 pootlecat

pootlecat
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 10 October 2006 - 09:04 PM

The problem I have is that I split one massive table into 3 smaller ones and I want the auto_increment column to start from '1' on 'line 1' and increase from there on all 3 tables. I was just hoping there would be some simple command I could do that would recalculate all the auto_increment values for me.

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 10 October 2006 - 09:07 PM

You don't want to do any of this... leave these values alone.  In theory you can just "recalculate" them yourself, and use whatever values you deem appropriate (but unless you can really convince me, I'm not going to tell you how).  Since it sounds like you're just starting out, I'm assuming that nothing is referencing these records via a FK.  The least bad method would be simply to copy the records over to a fresh table without their UID, and let MySQL take care of it.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users