Welcome to WebmasterWorld Guest from 54.211.101.8

Forum Moderators: open

Rebuild index id #

How to rebuild the id of primary keys

   
5:00 am on Oct 10, 2009 (gmt 0)

5+ Year Member



Hey guys and gals, just wondering if there is a simple way to rebuild the primary index ID numbers of my tables?

I have a content table, each has a primary auto incrementing key called ID. Over time, these values has fragmented. For example, it will go to 187, then skip to 240 and continue, and so on.

What I want to do is where it skips, overwrite 240 and start back at 188 and continue upward correctly. Is there an easy way to do this without manually correcting this?

By the way, the database is MySQL and I am using PHP.

8:47 pm on Dec 7, 2009 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



If you have other tables which use those values, this sort of operation is VERY risky. You'll have to write code that updates all the different joined rows with the new value for every single row.

If you aren't using those values anywhere else and just want to reorder them, it should be as simple as removing that column from the table and then re-adding a new auto incrementing column to the table.

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month