SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2007
    Location
    Toronto/Whitby ON Canada
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL ID organization question

    hello all,
    I find myself wondering if there is a way to keep the ID column of a table consecutive? for example when creating new entries in a table manually it is easy to keep the ID column as followed:
    ID
    1
    2
    3
    4

    now i have noticed when inserting new entries into a table or deleting them with PHP, MySQL will leave gaps in between. For instance instead of creating the next ID = 5 in the example above if entries have already been entered and deleted MySQL will store the next ID where it left off and your left with gaps like:
    ID
    1
    2
    3
    4
    11
    15
    etc etc

    im just wondering if there is a basic way to fix this or prevent it from happening with MySQL or if a PHP script would be the best option.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    the solution is: leave the gaps alone

    there is no need to do anything about them

    there, wasn't that easy?

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now asked 1,985,345,432,345,123,456 times on various forums, most of them answered by Rudy. Do people not search? ;-)


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
  •