View Full Version : Updating Primary auto increment table.
Jolten
02-07-2005, 04:34 AM
How can I reset an autoincrement database table to rebuild it's numbers?
Here's the scenario: I have a database table with 118 rows. Due to testing the first 82 rows are gone. So I want to reset the autoincrement field for all rows - 82 so row 83 is numbered 1, 84 = 2, 85 = 3 and so on.
I tried UPDATE autoincrement SET autoincrement = (autoincrement - 82) but that doesn't seem to work. I'm guessing maybe because the autoincrement field is the primary key for the database.
I know I could change these all manually... but can't it be done with one simple query?
Thanks
Zachery
02-07-2005, 10:47 AM
How can I reset an autoincrement database table to rebuild it's numbers?
Here's the scenario: I have a database table with 118 rows. Due to testing the first 82 rows are gone. So I want to reset the autoincrement field for all rows - 82 so row 83 is numbered 1, 84 = 2, 85 = 3 and so on.
I tried UPDATE autoincrement SET autoincrement = (autoincrement - 82) but that doesn't seem to work. I'm guessing maybe because the autoincrement field is the primary key for the database.
I know I could change these all manually... but can't it be done with one simple query?
Thanks
I don't think it can be done (or at least thats what I have been lead to believe)
As far as i know, you would need to drop the table make it again, then reimport your data and make sure the data was imported with the proper id's and not their old numbers ect.
Dean C
02-07-2005, 11:43 AM
You could take away the auto_increment. Go and change all the values and then change it back?
Jolten
02-07-2005, 01:48 PM
Thanks guys. I'm discovering the same thing. they can be edited manually but a query won't function.
here a way
hmm you can a temp table with auto increment and just
read from old and inset into new 1
then delete old table and recreat it and do the progrees again
way 2 :
$bla = select * from table name;
$i=0;
while ($bla2 = $DB_site->fetch_array($bla))
{
i++;
$DB_site->query("Upade table Set id='$i' ");
}
shoudl work
way 2 is better.
Jolten
02-07-2005, 02:06 PM
Thanks miz.. I'll try that.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.