Forum Moderators: open

Message Too Old, No Replies

auto increment varchar in mySQL

appending autoincrement with 0000 and ABC

         

arjun55

9:10 pm on Jun 23, 2009 (gmt 0)

10+ Year Member



hi,

i need to have an auto increment for a field where the field is a varchar i.e. i need something like

ABC0000234 to be incremented to ABC0000235 automatically on insert operation.

arjun55

11:32 am on Jun 24, 2009 (gmt 0)

10+ Year Member



anybody there with a solution please

LifeinAsia

3:52 pm on Jun 24, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I am not aware of anything like that.

The best solution I can offer is to make it 2 fields- one that is VARCHAR and one that is INT that is auto incremented. Then setup a trigger to populate the VARCHAR field based on the value of the INT field.

You'll need some additional logic for what to do for the next record after ABC9999999. Maybe make the characters defendant on (INT field)/10000000?

arjun55

7:38 pm on Jun 24, 2009 (gmt 0)

10+ Year Member



so any bright idea as to how to do the same.