SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    auto_increment question

    I have a database that uses the auto_increment to keep tack of the number of entries in my db. Say I have 20 rows and I delete 10 of them is there a way that when i add a new row the auto_increment will start back 11 instead of carrying on at 21?

    Thanks

  2. #2
    SitePoint Addict Guimauve's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in SQL Server it would be the following command:

    Code:
    DBCC CHECKIDENT ('MyTableName', RESEED)

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry I guess I should have mentioned this is a mySQL db

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    the correct answer is: you shouldn't want to reset those numbers

    especially if the number is going to be used anywhere other than this table

    the only purpose of an auto_increment is to provide unique numbers

    if you need the gaps filled, then there's a design problem, and you probably don't want to use an auto_increment
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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