Jump to content


Photo

Changing Auto-Increment Value


  • Please log in to reply
6 replies to this topic

#1 elioncho

elioncho
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 09 October 2006 - 07:32 PM

HI, I have a table that looks something like this:

CREATE TABLE orders(
  ID            INT(5) AUTO_INCREMENT NOT NULL,
  name        VARCHAR(40) NOT NULL,
  date        DATE NOT NULL,
PRIMARY KEY(ID,date) )

I want to change the value of ID to 1 again after certain time. What MySQL query can I use to make the field ID begin autoincrementing from number 1 again. Thanks..

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 October 2006 - 10:29 PM

Why would you want to do that?  The auto-increment value is an intrinsic part of the database, not some field you should manipulate at will. 
Legend has it that reading the manual never killed anyone.
My site

#3 elioncho

elioncho
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 10 October 2006 - 12:32 AM

Because I want that everytime a new year starts the count to begin at 1.

#4 pootlecat

pootlecat
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 10 October 2006 - 12:52 AM

It seems you want to know the same thing as me :)
I haven't found anywhere on Google that suggests it is even possible but hopefully someone here will know!

#5 fenway

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

Posted 10 October 2006 - 03:28 PM

I've posted elsewhere on how to do this, much to my shagrin... if you want to empty out the table properly, TRUNCATE it, and MySQL will take care of the rest.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#6 pootlecat

pootlecat
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 10 October 2006 - 05:15 PM

I don't know about elioncho but I want to keep my data and just redo the auto_increment column :)

#7 fenway

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

Posted 10 October 2006 - 07:22 PM

The question is "why?"...
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