Web Hosting Talk







View Full Version : help reorganize database by id


jennymac
04-27-2007, 03:47 PM
I have a large mysql database and I want to reorganize it by putting it in order again...

the auto increment is the "id" where as of now I have
id:
1
2
7
8
12
etc...

----->>

I would like to have it as:
id:
1
2
3
4
5
etc...

I would like to put everything in order again, is there a way to do it via SSH?

Let me know how to do it if you know.

Thank you very much...

Burhan
04-28-2007, 04:41 AM
In database world, there is no such concept as 'order'. You cannot control the way records are entered into a table, this is something that the database handles by itself.

You can control in what order the results are returned to you using the proper SQL queries, so in your case, you would use 'SELECT [some columns] FROM [some table] ORDER BY [your id field]'

Extreme43
04-28-2007, 09:45 AM
As long as nothing is relational (such as a settings table where the setting is identified by a name or similar), i just run a query than a loop. the first query to increase the id by 10000 and the loop runs over each row in ascending order changing the values from 10001 to 1, 10002 to 2, 10005 to 3, 10007 to 4 ect ect.

But i am guessing it is relational in some way, in this case - you just leave it be. Does it matter what the ID is?

sasha
04-28-2007, 10:38 AM
If you drop id field and create it again as primary auto-increment key, it will be in order. I do not see good reason to do this and if you referenced this id field anywhere else, it will break that association.

ActivI
04-28-2007, 04:47 PM
Like it was already stated, you should not interfeer with the way the data is being organized. Your field of action is the definition of the tables, indexes, data files, etc. From there, it's up to the server to organize it based on your indexing and queries.

Just one thing. Is there any particular reason to do this? Or it's purely eye-candy? If there is please explain, in detail, the problem you have in hands. I'm pretty confident there will be another solution to your problem other than this.