How can I reset the ID in the database back to 1?

Discussion in 'PHP' started by jehzlau, Jul 22, 2007.

  1. #1
    How can I reset the ID in the database back to 1? Because when I add another info for example, in the database, there is an ID and a Name

    The ID was auto incremented so after adding 1, and a name sample: Apple, i'll add another name, for example Orange, and the ID auto increments to 2, and so on...

    i want to delete the 2 entries, then add another 1, but it starts now to 3...

    3 Banana

    then add another 1, then it add another number, so the ID is now 4... even if i refresh and delete cookies, it continues to increment...

    my question is, how can i reset it back to 0? :(

    so that when I add a new entry, it starts again to 1? :(

    need help im so nooob at this stuff T__T
     
    jehzlau, Jul 22, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
  3. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #3
    truncate tblname;

    alter tblname auto_increment = 0;
     
    ansi, Jul 23, 2007 IP
  4. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #4
    First this is a mysql question and not really a php question. ;)

    If the table has data in it already then it will not keep the # setting even if you chnage it. Because mysql will see the next id number from the previous auto_inc number. You can in phpMyAdmin 'empty' the table and it will reset the auto number, but that will leave you with a blank table. The other is to goto the options page and set the number there, but on the next auto_increment will go to what ever the next # is.

    If you don't have indexed pages that use the id's for anything. I would recommend you remove all the id entry's and then readd them. That way they reorder themself and you end up with a lower next number if you have removed entry's.
     
    exodus, Jul 23, 2007 IP
  5. jehzlau

    jehzlau Active Member

    Messages:
    301
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    73
    #5
    wow thanks for all the very informative replies.. hehe.. i can't find a mysql forums, that's why i posted it here.. hihihi.. thanks ^__^
     
    jehzlau, Jul 23, 2007 IP