/    Sign up×
Community /Pin to ProfileBookmark

How to generate alphanumeric auto increment id in mysql?

How to generate alphanumeric auto increment id in mysql?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@SparoHawkNov 02.2012 — 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.
Copy linkTweet thisAlerts:
@DerokorianNov 02.2012 — You could always use [url=http://dev.mysql.com/doc/refman/5.1/en/miscellaneous-functions.html#function_uuid]uuid()[/url]
Copy linkTweet thisAlerts:
@NogDogNov 02.2012 — 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).
Copy linkTweet thisAlerts:
@deepthi_21456authorNov 05.2012 — I have to generate id like this ASP01,ASP02......
Copy linkTweet thisAlerts:
@NogDogNov 05.2012 — I have to generate id like this ASP01,ASP02......[/QUOTE]

In that case I would go with my suggestion of just using an auto-increment integer column, then prepend the "ASP" part when actually outputting it to the user:
[code=php]
printf('ASP%02d', $integerValueFromDatabase);
[/code]
×

Success!

Help @deepthi_21456 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...