auto increment varchar !

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 15
Joined: Wed Mar 27, 2013 7:59 am

Thu Apr 04, 2013 2:41 pm

ideas anyone ?

php-forum Super User
php-forum Super User
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

Thu Apr 04, 2013 8:24 pm

Better to split that varchar field into two separate fields, one of varchar to keep the character part and the other should be integer or numeric on which you can enable auto increment.
e.g. field_1 will be 'C' and field_2 will be 1,or 2, or 3 etc. When you display you can concatenate both as C1 or C2 etc

The other option will be to increment the field on the application side and just save it to the varchar field in the database.e.g. if the original value was C001 in the table, increment it to C002 and save it so that the new field value will be C002.

php-forum Fan User
php-forum Fan User
Posts: 974
Joined: Mon Oct 01, 2012 12:32 pm

Fri Apr 05, 2013 1:36 am

You can also set an insert trigger, as said in your other thread, so that it''s automatically done for you whenever a row is inserted. here's an example so you see how easy it is. ... yntax.html

Post Reply