Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Auto_increment functionality !!

    Hi

    Ok so here is my problem. I have a database with a table named items with a field named Item_ID. This field is set as auto increment. When I enter data into my database however it does not get the last number entered and add one to it, which I thought it would do.

    It seems to remember the previous number used. Which is not good because in the meantime if I add and delete records as you do. Then look at the table I end up with gaps in the numers. i.e the Item_ID column will go 12, 13, 26,27, 190 ... you get what I mean.

    Its just abit anoying cos to me its a waste. Is there a way to set-up the auto-increment to work like that ??

    I have no idea if this is possible but I am just wondering.

    Thanks


  • #2
    New Coder
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It is normal functionality and to my knowledge you can't use it otherwise.

    But why would this be bad? in my opinion it's a good thing. This way you'll never have some old unremoved reference (to some data that was removed) that is pointing to the wrong data in your database...

    And I don't think it's that much of a waste really

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As wichetael said, having it so that it used any missing numbers could easily result in a badly linked site.
    If there was a page that linked to show_items?id=77 and you deleted 77, you could either never fill that slot or overwrite it.
    If you never used it again, trying to access the page would output your row_not_found message.
    If you overwrote it, your visitors might get weird items when looking for normal ones.

    I find it best to delete and then recreate all db tables just before going live. This resets auto-inc to zero ready for refilling properly.

    You could also count all rows returned and minus that from the highest id number to find how many rows you'd ever deleted.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yer i see what your saying but I just didn't expect it to be like that I don't really know why but hey ...

    I guessed I thought if you had a limit set on the auto increment field then it would fill up sooner than it needed to.
    And because of the way of my pages are set-up and run you wouldn't end up with broken links etc.

    Anyway thats that then . . .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •