Author Topic: [SOLVED] mysql table back to 1 after delete  (Read 673 times)

0 Members and 1 Guest are viewing this topic.

Offline anonTopic starter

  • Enthusiast
  • Posts: 134
  • Duffman!
    • View Profile
    • Steve Smit - Novice Blogging Ninja
[SOLVED] mysql table back to 1 after delete
« on: January 01, 2008, 11:00:50 AM »
I have a table with auto-increment. When i delete all data in the database, and then enter a new value, the id won't return to 1, it will auto-increment after the last deleted value.

e.g the new values id will be 5, not 1.

How do i get it to reset?
redZERO :: Web Engineering and Deisgn - At redZERO, we provide Web Engineering and Web Design services.

Steve Smit - Novice Blogging Ninja! is my personal blog. Visit for some interesting stuff and helpful tips on web design, blogging and life.

Offline toplay

  • Staff Alumni
  • Freak!
  • *
  • Posts: 6,272
    • View Profile
Re: mysql table back to 1 after delete
« Reply #1 on: January 01, 2008, 11:06:39 AM »
It's in the manual:

To change the value of the AUTO_INCREMENT counter to be used for new rows, do this:

ALTER TABLE t2 AUTO_INCREMENT = value;
« Last Edit: January 01, 2008, 11:07:48 AM by toplay »

Offline revraz

  • Freak!
  • Posts: 6,866
  • Gender: Male
  • Problems Resolved: 352
    • View Profile
Re: [SOLVED] mysql table back to 1 after delete
« Reply #2 on: January 01, 2008, 11:12:33 AM »
If you have PHPMyAdmin, you can do it in there as well.
If I can't make it better, then I'll make it worse, but it definitely won't be the same.

Offline anonTopic starter

  • Enthusiast
  • Posts: 134
  • Duffman!
    • View Profile
    • Steve Smit - Novice Blogging Ninja
Re: [SOLVED] mysql table back to 1 after delete
« Reply #3 on: January 01, 2008, 11:48:01 AM »
How do i do that in phpmyadmin?
redZERO :: Web Engineering and Deisgn - At redZERO, we provide Web Engineering and Web Design services.

Steve Smit - Novice Blogging Ninja! is my personal blog. Visit for some interesting stuff and helpful tips on web design, blogging and life.

Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Mind Boggling!'
  • *
  • Posts: 15,443
  • Gender: Male
    • View Profile
Re: mysql table back to 1 after delete
« Reply #4 on: January 01, 2008, 12:25:55 PM »
If you really want to empty a table, use TRUNCATE, and you won't have this problem.
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

Offline anonTopic starter

  • Enthusiast
  • Posts: 134
  • Duffman!
    • View Profile
    • Steve Smit - Novice Blogging Ninja
Re: mysql table back to 1 after delete
« Reply #5 on: January 01, 2008, 12:29:06 PM »
I don't want to just empty the table, i want it to reset back to 1 afterwards. Doesn't do that, carries on counting after I have deleted the entire table.
redZERO :: Web Engineering and Deisgn - At redZERO, we provide Web Engineering and Web Design services.

Steve Smit - Novice Blogging Ninja! is my personal blog. Visit for some interesting stuff and helpful tips on web design, blogging and life.

Offline revraz

  • Freak!
  • Posts: 6,866
  • Gender: Male
  • Problems Resolved: 352
    • View Profile
Re: [SOLVED] mysql table back to 1 after delete
« Reply #6 on: January 01, 2008, 12:37:14 PM »
Under the Table, go to Operations.  You can set it there.

How do i do that in phpmyadmin?
If I can't make it better, then I'll make it worse, but it definitely won't be the same.

Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Mind Boggling!'
  • *
  • Posts: 15,443
  • Gender: Male
    • View Profile
Re: mysql table back to 1 after delete
« Reply #7 on: January 02, 2008, 09:16:09 AM »
I don't want to just empty the table, i want it to reset back to 1 afterwards. Doesn't do that, carries on counting after I have deleted the entire table.
You deleted the entire table, but you don't want to empty it? What does that mean?  TRUNCATE deletes and resets the counter properly.
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

Offline anonTopic starter

  • Enthusiast
  • Posts: 134
  • Duffman!
    • View Profile
    • Steve Smit - Novice Blogging Ninja
Re: mysql table back to 1 after delete
« Reply #8 on: January 02, 2008, 03:30:56 PM »
(not being smarmy here) I said I don't just want it to delete....

I want it to delete the entire table AND reset counter

I understand that Truncate does that now.
redZERO :: Web Engineering and Deisgn - At redZERO, we provide Web Engineering and Web Design services.

Steve Smit - Novice Blogging Ninja! is my personal blog. Visit for some interesting stuff and helpful tips on web design, blogging and life.