Page 1 of 1
store current auto increment value
Posted: Tue Aug 25, 2009 8:14 pm
by greedyisg00d
I have a Student table and StudNo field which is set as primary key and auto increment is enabled. My problem is when I delete a specific row I noticed that the auto increment value remains the same. So is there a way to get the current auto increment value and store it to a variable? Sample code is much appreciated. Thanks
Re: store current auto increment value
Posted: Tue Aug 25, 2009 9:22 pm
by ocpaul20
in mysql, I dont think an autoincrement field will decrement if you delete a record! It just keeps on incrementing. You will have to re-write the table to somewhere else if you need the autoincrement numbers to be sequential after you delete a record.
There is a mysql command to get the contents of the autoincrement field I believe. Although it might be a php mysql_ function I cannot remember, but I know I have seen it available.
Re: store current auto increment value
Posted: Tue Aug 25, 2009 10:09 pm
by requinix
Whatever you want to do, don't. Not this way. An auto-increment field is the square peg solution to the round hole problem you have - find something else. Want advice: describe what you're trying to do.
(PS: ocpaul20 is probably thinking of
mysql_insert_id but that does something slightly different.)