Web Hosting Talk







View Full Version : Isn't there an easier way?


lexington
07-10-2007, 05:34 AM
Hello, a while back I found a phpBB script that basically trucated a db table and added all of the data back but resynced the IDs so that they were all in order. For some reason I want to do this with just about every DB on different sites heh. If the DB table isn't too large, I export the data, truncate the table, and manually change the IDs so that they are in order and insert the data back. For much larger tables, how hard would it be to create a script that can perform this task automatically? Some db tables share the same IDs so it would have to be able to assign the correct IDs.

ActivI
07-11-2007, 12:23 PM
Why would you want to order the IDs? Look at it this way the "ID" table is for the database to use. If you want to apply some fancy custom organization add a column to do it.

I seriously don't understand why you want to do such thing. Could you enlight us on your needs, business rules, etc?

As for your direct question: the larger the table the longer it will take, specially if you are inserting rows into an indexed table.

avocado
07-11-2007, 04:38 PM
If for some odd reason you absolutely, positively MUST do this, you could step through the table, and for each missing ID, change the ID of the highest-ID remaining row to have the missing ID. That should fill in the gaps without having to re-insert every single row of the table. Remembering, of course, to update any other table that uses that ID as a foreign key.

I agree, though, it seems like a silly thing to bother doing.