Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2012
    Posts
    3

    Unanswered: problem with AUTO_INCREMENT

    hi all

    I have created a table with: id | message | date

    at first, all seemed to work fine BUT the id (AUTO_INCREMENT) doesn't reset itself back to 1 when i delete all the rows, it continues counting from the last row example

    id message
    1 xxxxx
    2 xxxxx
    3 xxxxx

    now if i delete where id=3, and then insert a new row, it will look like this:

    id message
    1 xxxxx
    2 xxxxx
    4 xxxxx

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    That is the correct, expected behaviour.

    Can you explain to us why you'd want it any other way?
    George
    Home | Blog

  3. #3
    Join Date
    Jan 2012
    Posts
    3
    Quote Originally Posted by gvee View Post
    That is the correct, expected behaviour.

    Can you explain to us why you'd want it any other way?
    ah nvm then, i can do this a different way its to do with a program im writing in assembly to work with the db.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Before you go ahead with your other method can you tell us why you need a perfectly sequential identifier for your records? I don't like to say it but chances are you have a flaw in your design.
    George
    Home | Blog

  5. #5
    Join Date
    Jan 2012
    Posts
    3
    Quote Originally Posted by gvee View Post
    Before you go ahead with your other method can you tell us why you need a perfectly sequential identifier for your records? I don't like to say it but chances are you have a flaw in your design.
    I've not worked with SQL for a very long time so i forgot that AUTO_INCREMENT works in the way it does. I was trying to delete a row based on the selected index of a listbox item but of course that would fail sinse the list box index could be 3 and the ID in the sql table could be 4. So instead i'm using listview32 API with a column for the ID, this way i can delete a row using the correct id from the sub column. And now everything is working fine, ready for my client

  6. #6
    Join Date
    Jul 2010
    Location
    ISHHHH
    Posts
    130
    If you want to get sequence after deleting the row u had to insert value directly to the auto increment column
    WiTh Tnks & ReGaRdS
    mAtHuKuMaLi

Posting Permissions

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