Question
#1

hello, I am using mysql now and could anyone tell me how to, let's say gang id 4 deletes his gang then the next one who creates a gang will take that id instead of following the AUTO_INCREMENT PRIMARY KEY and have gang id 5

What would the function be?

Thank you
Reply
#2

If I remember correctly, that is impossible with AUTO_INCREMENT. Lets say you have ID 1, 2, 3, 4 and gang ID 2 gets deleted. You can not set the AUTO_INCREMENT to use 2 next time one is created and then continiue at 5.

I might be wrong of course!

You could assign the ID manually, that way you could store the ID that was deleted and then use it when someone creates a new one. It requires some thinking and coding but it is possible!

Good luck
Reply
#3

I really don't want to store the id for later use..

But isn't there really anything where you can find the nearest empty slot? I've seen some stocks for this, but I need it for mysql. Anyway, I will try do some more research if anyone knows a good way to do it please reply
Reply
#4

Finding the empty slot is possible. but because you have AUTO INCREMENTATION you can not insert a new gang with that ID. Whatever number you query as the id, the auto incrementation will just use currentid+1.
I hope you understand what I mean ;p
Reply
#5

I could just remove the AUTO INCREMENTATION. Then select from the query and add a 1+ each time a new gang creates. This way you can find the emplty slot right? But I like to use AUTO INCREMENTATION because then I can use mysql_insert_id which I find very useful.. I guess I have to do that. Also, let's say the gang id 1 gets removed, would it be possible to like "push" all the ids in the right order? So then the gang id 2 would be 1 and id 3 be 2, etc?

Thanks for your help btw
Reply
#6

I think that would be possible by removing every gang that is higher than the removed id, then setting the AUTO INCREMENTATION id to the removed id and then readding the gangs you removed.
Example:
- Gang ID 1
- Gang ID 2
- Gang ID 3
- Gang ID 4

id 2 gets removed

- Gang ID 1
- Gang ID 3
- Gang ID 4

Delete everything after the removed gang

- GANG ID 1

Set the AUTO INCREMENTATION to 2
Readd the Gangs

- Gang ID 1
- Gang ID 2 (Was 3)
- Gang ID 3 (Was 4)

Like I said, it is possible. I could show you how to set the AUTO INCREMENTATION value but I really suggest you to leave it as it is. In my opinion it is not worth the effort!
Reply
#7

Yeah I guess, not worth it..

Thank you anyway.

Rep.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)