autoincrement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • leegold2

    #1

    autoincrement

    Say I got 20 records in a MYSQL DB. I go into PHPMyAdmin and drop (it's
    that "X" icon) the last three (3) records. Then I run a PHP script to
    add 3 records to the DB. I have an autoincrement PK field and I'm using
    mysql_insert_id to add fields in other tables subsequently... Well, the
    auto-increment starts at 21. Here's my question:

    What would be the method to just at the end (ie. 18-20) "really" delete
    those "ghost" records or reset somehow so that auto-increment knows to
    start at 18 again.?

    I got no problem with holes (ie. 1,2..5,6) but i want stuff at the wiped
    if possible.
  • Jonathan Martens

    #2
    Re: autoincrement


    "leegold2" <leegold@nospam .net> wrote in message
    news:VWTDd.1296 $F97.973@trnddc 06...[color=blue]
    > Say I got 20 records in a MYSQL DB. I go into PHPMyAdmin and drop (it's
    > that "X" icon) the last three (3) records. Then I run a PHP script to add
    > 3 records to the DB. I have an autoincrement PK field and I'm using
    > mysql_insert_id to add fields in other tables subsequently... Well, the
    > auto-increment starts at 21. Here's my question:
    >
    > What would be the method to just at the end (ie. 18-20) "really" delete
    > those "ghost" records or reset somehow so that auto-increment knows to
    > start at 18 again.?
    >
    > I got no problem with holes (ie. 1,2..5,6) but i want stuff at the wiped
    > if possible.[/color]

    Auto-increment fields are mostly used for relationships between tables so
    deleting records and taking those vacant numbers for the new entered data
    would link this new record to some other record in some other table that is
    not meant to be linked to at all. It causes serious relationship problems
    and therefore it is (I think and am not completely sure) not supported.

    Jonathan


    Comment

    • Bill Karwin

      #3
      Re: autoincrement

      leegold2 wrote:
      [color=blue]
      > What would be the method to just at the end (ie. 18-20) "really" delete
      > those "ghost" records or reset somehow so that auto-increment knows to
      > start at 18 again.?[/color]

      Here's an excerpt from
      http://dev.mysql.com/doc/mysql/en/ex...NCREMENT.html:

      "Note that in this case (when the AUTO_INCREMENT column is part of a
      multiple-column index), AUTO_INCREMENT values will be reused if you
      delete the row with the biggest AUTO_INCREMENT value in any group. This
      happens even for MyISAM tables, for which AUTO_INCREMENT values normally
      are not reused.)"

      So it sounds like you can't reuse the auto-generated values, unless they
      are part of a compound (multi-column) key.

      Regards,
      Bill K.

      Comment

      • Hal Halloway

        #4
        Re: autoincrement

        Jonathan Martens wrote:[color=blue]
        > "leegold2" <leegold@nospam .net> wrote in message
        > news:VWTDd.1296 $F97.973@trnddc 06...
        >[color=green]
        >>Say I got 20 records in a MYSQL DB. I go into PHPMyAdmin and drop (it's
        >>that "X" icon) the last three (3) records. Then I run a PHP script to add
        >>3 records to the DB. I have an autoincrement PK field and I'm using
        >>mysql_insert_ id to add fields in other tables subsequently... Well, the
        >>auto-increment starts at 21. Here's my question:
        >>
        >>What would be the method to just at the end (ie. 18-20) "really" delete
        >>those "ghost" records or reset somehow so that auto-increment knows to
        >>start at 18 again.?
        >>
        >>I got no problem with holes (ie. 1,2..5,6) but i want stuff at the wiped
        >>if possible.[/color]
        >
        >
        > Auto-increment fields are mostly used for relationships between tables so
        > deleting records and taking those vacant numbers for the new entered data
        > would link this new record to some other record in some other table that is
        > not meant to be linked to at all. It causes serious relationship problems
        > and therefore it is (I think and am not completely sure) not supported.[/color]

        Right i understand that now. thanks!

        [color=blue]
        >
        > Jonathan
        >
        >[/color]

        Comment

        Working...