How to generate alphanumeric auto increment id in mysql?
Printable View
How to generate alphanumeric auto increment id in mysql?
You cannot do it by "normal" means, as in MySQL configuration.
You can "simulate" it using code.
At most, you can create a 2 column configuration in a table, have a column with your alpha prefix and a second column with the auto_increment integer, than you set those fields together as the primary key. However, you will need to send the alpha prefix every time and the DB will do the integer auto_increment accordingly.
You could always use uuid()
The best answer probably depends on what you mean by an alphanumeric ID. Does the alpha part increment in some way, and if so, what are the rules for that? If the alpha part is static, then you don't even need it in the DB: just prepend it to the numeric ID when you output it (perhaps using [s]printf() or similar functions to prepend zeroes so that it's a fixed length?). Without know the full requirement, though, we're all just speculating (or least I am).
I have to generate id like this ASP01,ASP02......