Does anybody know the code to insert in the sql command box in phpMyAdmin to make it add an auto incremented column? I want to make it so it will automaticly add a number for each row. I’m not that good with mySQL and I tried some stuff but no luck. Thanks for the help! ?
@JickauthorMar 20.2004 — #I tried it without making a new table and just tried it on my exsiting one and it worked. Is there a reason I would have to create a new table because for one it seems to have worked without creating a new tables and two I don't really want to have to do that since I already have stuff in the table. Thanks for your help.
P.S. Ok, say I have three rows in the table, what would happen if I deleted row 2 and then added a new one? I ask cause each row has to have an id which is unique and cannot be used twice unless it dosen't exsist. Thanks for all your help.
@The_CheatMar 20.2004 — #Is there a reason I would have to create a new table because for one it seems to have worked without creating a new tables[/quote] Whoa, you're right! ? my bad on that
so really the only thing wrong was not making it a primary key
@The_CheatMar 20.2004 — #P.S. Ok, say I have three rows in the table, what would happen if I deleted row 2 and then added a new one? I ask cause each row has to have an id which is unique and cannot be used twice unless it dosen't exsist. Thanks for all your help.[/quote] the new one added would be 3, not 2.. (I'm pretty sure.)
@JickauthorMar 20.2004 — #I did some more looking and I asked the last question toatally wrong. Sorry about that. Lost my head for a minute. :p
Here is the correct question. How can I make it so the id will always be in order. I did some more looking and it appears that when I delete say row 3 and then add one it ends up being row 4. How can I make it so if there is no row 3 it will add that instead of adding the next number.
@solavarMar 20.2004 — #With auto increment, if you delete record number 5, the next record will be record number 6. In other words, you can not replace deleted numbers.
So each time a new record is added, a new number is generated for it, even when the previous record has been deleted.
@The_CheatMar 20.2004 — #[i]Originally posted by mjdimick [/i]
[B]I did some more looking and I asked the last question toatally wrong. Sorry about that. Lost my head for a minute. :p
Here is the correct question. How can I make it so the id will always be in order. I did some more looking and it appears that when I delete say row 3 and then add one it ends up being row 4. How can I make it so if there is no row 3 it will add that instead of adding the next number.
Hope I got it right this time lol... [/B][/QUOTE] why would you want it to do that? any purpose?
@JickauthorMar 20.2004 — #Well I have a page where these database rows are displayed. They are displayed by their row id which is a number and I found that it screws up the order of them when I delete one and add one. So by doing what I want I believe it will keep the order correct! ?
@JickauthorMar 20.2004 — #I now found another problem. Because of it making it the next number it might run out of numbers to use because with my script there will be lots of deleting and adding going on so it will keep making it a higher number and to my knolage the auto increment option only allows a certain amount of numbers so it would stop working at some point. Plus I think it would just be better and more efficiant and just makes more sense the way I want it in my opinion. Thanks for your help. ?
@JickauthorMar 20.2004 — #Well the numbers could easily get up to past the 1000's with how much it would be used and I would just feel better if I knew that all the numbers were being used before it added more. ?
@The_CheatMar 20.2004 — #you could change it to BIGINT(20) UNSIGNED which would go up to more than you could probably use up in your lifetime. ? 18,446,744,073,709,551,615
@JickauthorMar 20.2004 — #Ok, I changed it to that but I was wundering if you could still tell me how to make it do what I wanted because I would just like to know for future refrence. Thanks for all your help! ?