#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    9
    Rep Power
    0
    I have in one of my tables a row that is set to a unique ID number for that entry. It is today calculated by checking for the next "empty" row in that category. I need to add a functionality that will allow the creator of that entry to delete it if necessary. That however causes some problems that I could work around if the ID was auto-incremental instead. Now the question is. Can I change that cell to autoinc without breaking anything, and just remove the calculation of the new ID from the code? Or will that cause any problems on the existing data?

    Reg, Stefan
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,645
    Rep Power
    4492
    yes, you can change it to auto_increment.
    the mysql statement would be:

    alter table <table> change column <old_column_name> <new_column_name> auto_increment;

    you'll need alter privs to do this.

    just FYI, if you have an column, say ID, that has values like 1,3,5,7. when you change that to auto_increment, it will start with 8 and start incrementing, it won't go and fill in the missing values. at least that's what i saw in the little test i ran.

    if you need to set the ID number of the last auto_incremented row in PHP you can use:

    $id = mysql_insert_id($link_id);

    Hope that helps, it not, spend my $0.02 on something nice...

    ---John Holmes
    ---www.SepodatiCreations.com

Similar Threads

  1. question about mysql query for html search form
    By adamscaa in forum MySQL Help
    Replies: 5
    Last Post: January 16th, 2004, 08:59 AM
  2. Replies: 4
    Last Post: January 14th, 2004, 05:22 AM
  3. Replies: 15
    Last Post: January 8th, 2004, 05:54 PM
  4. MySQL Perl Question
    By ryche88OM in forum MySQL Help
    Replies: 0
    Last Post: January 6th, 2004, 09:32 PM

IMN logo majestic logo threadwatch logo seochat tools logo