www.webdeveloper.com
Results 1 to 6 of 6

Thread: How to generate alphanumeric auto increment id in mysql?

  1. #1
    Join Date
    Jul 2012
    Posts
    32

    How to generate alphanumeric auto increment id in mysql?

    How to generate alphanumeric auto increment id in mysql?

  2. #2
    Join Date
    Jul 2007
    Posts
    386
    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.

  3. #3
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    You could always use uuid()

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    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).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jul 2012
    Posts
    32
    I have to generate id like this ASP01,ASP02......

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    Quote Originally Posted by deepthi.21456 View Post
    I have to generate id like this ASP01,ASP02......
    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:
    PHP Code:
    printf('ASP%02d'$integerValueFromDatabase); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles