Posts: 107
Threads: 21
Joined: Jun 2011
Reputation:
0
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
Posts: 790
Threads: 7
Joined: Mar 2008
Reputation:
0
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
Posts: 107
Threads: 21
Joined: Jun 2011
Reputation:
0
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
Posts: 790
Threads: 7
Joined: Mar 2008
Reputation:
0
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
Posts: 107
Threads: 21
Joined: Jun 2011
Reputation:
0
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