Page 1 of 1
Incremental number
Posted:
31. July 2007 18:12
by SirChick
If i use an incremental number as unique and primary key for users.... so first record is 1 then next is 2 etc
Say i delete row 3 and 4 how can i get it so that the next 2 registrations that occur will take up ID 3 and ID 4, instead of going to the end of the database? would this require a script or is there a method of doing it in the database itself?
oops: please move to the english board! my bad!
Posted:
31. July 2007 20:37
by martinpre
what should the program do if you hav user 1,2,3 and 4 and you delete user 2 and then a new user come?
Re: Incremental number
Posted:
31. July 2007 23:03
by jrav
SirChick wrote:Say i delete row 3 and 4 how can i get it so that the next 2 registrations that occur will take up ID 3 and ID 4, instead of going to the end of the database?
With the version of mySql I am using, it works like this by default....have you experienced behaviour different than this?
Posted:
01. August 2007 13:02
by SirChick
umm i think you misread.
I want it to full up the numbers that are not ther. An example:
1
2
3
4
5
say i remove row 3.
1
2
4
5
now the newest person signs up, by default it becomes number 6. But i want it to be number 3 cos number 3 is not there. Meaning it will fill up the ID numbers that have been removed before just going on to the last ID number like so:
1
2
4
5
3
Posted:
01. August 2007 17:47
by jrav
Posted:
01. August 2007 18:29
by SirChick
Ok, i dont have the confidence with that yet thats for sure lol
Posted:
01. August 2007 20:02
by jrav
You can do it!
In the file where you delete users, add....
ALTER TABLE tableName AUTO_INCREMENT = 1;
after the deletion. Change tableName to the name of your table and it should work as requested.
Posted:
02. August 2007 00:39
by SirChick
ok so i add this php to it at the end of the code?
Posted:
02. August 2007 00:41
by SirChick
what exactly will that code do just so im sure ya understood what i needed...