0

I hope I can explain this. I have a table which contains a field named ID. This is set as PRIMARY. Because users registered on my site and after that deleted their accounts (so a lot of rows got deleted, too) the table rows now are jumping, for example, from ID 33 to 3333.
What I want to do is to rewrite, somehow, the ID field, so the rows will start from 1 and end at the last row. Is there a way to do this?
Thanks!

2
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by debasisdas
0

the table rows now are jumping

I really do not understand what exactly you mean by that, are you trying to re arrange the ids starting from 1 and increment by 1 till the last record ?

0

Yes, exactly. Now I have ID from 1 to 10, for example, then the next is 15 to 20, then again after 20 is 33 to... etc. I'd like them to rearrange them so they start from 1 and end with the last row number; now I have 15000 rows but the last row has the ID 223000 - it should have the ID 15000.

0

I want to understand what is the problem if the id values are not continuous. As you said this field is the PK of the table, is it not referred by any other table ?

0

No, the database has only one table. I don't know if there's a real problem, I just want to 'keep things in order' :) Besides, maybe it will make the database a little smaller and faster, too.

0

If the records are already deleted and the ID field is the PK of the table it is not going to have any effect on size or performance.

0

I don't want to sound like an ungrateful bastard, but are you trying to help me with what I want or not?!
Anyway, for the posterity: apparently is very easy to do this, it took a noob 2 days to realize :) - Solution: just delete the field and create it again, as PRIMARY.

0

Your post shows you are new to using database so trying to use an unrealistic approach.

I don't see a single benefit of this approach, neither size nor performance wise.

What you will do when again some of these (modified) ids gets deleted, you again have to maintain the data. I think this is the only outcome of this process, more frequent maintenance.

If you still think i was not trying to help you and you are adamant to use your approach, god bless.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.