SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple mySQL question (re: delete)

    Hi All,

    I have a question about mySQL databases related to deleting a row:

    I've noticed that when I delete a row (using php) in the database, that the same id# is never used again.

    For example, I delete row 2. Then, when I add a new record to the database, that new record is given a different id number, not 2.

    My question: is this how it is supposed to work? As a result of this I have a record assigned with id # 10, even though I only have 6 records in the database.

    Hope I am making sense,

    Thanks in advance!

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes that's how it's supposed to work. AUTO_INCREMENT IDs are meant to be unique identifiers and nothing more. MySQL simply stores the last value generated as a property of the table, and adds one to get the next ID.

    If you need a row count, use COUNT(), not MAX(ID).

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Dan. Glad to know that I haven't done something weird with my database configuration.


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
  •