Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member
    Join Date
    Oct 2007
    Posts
    241
    Member #
    15910
    In mysql, my primary key is id column and it is autoincrement. sometimes i do a mistake when entering something and when i delete the last row, the utoincrement keeps counting for the next row. for example, if i delete the row with id =37, the next row does not become 37, but keeps counting from 38. how can i make the next row count from where it left, so that there wont be any gaps between id numbers? because this way whenever i make a mistake and have to delete a latest entry, the id number keeps counting. OR it really doesnt matter ?

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    It does not really matter, however if you really want to do this you can drop the auto increment column and then add the column. All rows will now have the number (starting at 1,2 3 etc)

    However this does mean you will lose any data in that column, and in my opinion is inefficient.

    It is okay to have gaps, if you are worried that because there are gaos you will never truly know how many actual rows are in the table, fear not, this can be done.

    Read http://dev.mysql.com/doc/refman/5.0/...increment.html for more information.

  4. #3
    Senior Member
    Join Date
    Oct 2007
    Posts
    241
    Member #
    15910
    thank you.
    also when you say "add the column" do you mean deleting the auto increment column and adding it back again, in which case all rows will now be numbered with no gaps? this new numbering is including the exitsing rows, or starting with new rows only?

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Yes, dropping the column and then adding the same column back again.

    That would work on all rows, whether they were created before the drop or after the replacement column was made.


Remove Ads

Posting Permissions

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

Search tags for this page

auto increment means

,
auto increment what it mean
Click on a term to search for related topics.
All times are GMT -6. The time now is 10:44 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com