homepage Welcome to WebmasterWorld Guest from 54.205.254.108
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Rebuild index id #
How to rebuild the id of primary keys
xKillswitchx




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

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.

 

whoisgregg




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved