June 22nd, 2000, 02:26 AM
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?
June 22nd, 2000, 07:51 AM
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...