Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
Thread: Condense a table
10-06-2011, 03:48 AM #1
- Join Date
- Jan 2011
- Thanked 0 Times in 0 Posts
Condense a table
Is there any way to condense down the primary key of a table if there are missing numbers?
For example, the primary key is a number from 1 to 100 and it has random numbers missing from rows being deleted.
So it would end up reading:
Last edited by Celestial; 10-06-2011 at 01:52 PM.
10-06-2011, 05:32 AM #2Code:
CREATE TEMPORARY TABLE clone LIKE mytable; INSERT INTO clone SELECT * FROM mytable; TRUNCATE mytable; INSERT INTO mytable ( all, fields, except, auto, increment, field ) SELECT all, fields, except, auto, increment, field FROM clone ORDER BY auto_increment_field; DROP TEMPORARY TABLE clone;Be yourself. No one else is as qualified.
10-06-2011, 05:33 AM #3
The difficulty with that, if it's not obvious, is that it is slow and clumsy and you better not be making any changes to the table in some other thread while this is going on.Be yourself. No one else is as qualified.