Discussion:
auto incerment string with number
(too old to reply)
Vignesh
2011-11-08 21:05:53 UTC
Permalink
We know that id of any table is of integer type and auto-increment in
that table is fine. But my problem is that i want to increment a
combination of string and integer. For example String : ABC is the
starting code for the unique id.

First Id of my table should be primary key and

ie ABC10001, ABC10002,..... and so on.

Without using another key as auto-increment. Please do not use two
type of unique key.
www.1-script.com
2011-11-09 06:36:19 UTC
Permalink
responding to
http://www.1-script.com/forums/mysql/auto-incerment-string-with-number-8947-.htm
Post by Vignesh
We know that id of any table is of integer type and auto-increment in
that table is fine. But my problem is that i want to increment a
combination of string and integer. For example String : ABC is the
starting code for the unique id.
First Id of my table should be primary key and
ie ABC10001, ABC10002,..... and so on.
Without using another key as auto-increment. Please do not use two
type of unique key.
If you are not planning on incrementing the string part
like
ABC99999
ABD00001
ABD00002
...
ABD99999
ABE00001
...

then you can use CONCAT with your SELECT statements like:

SELECT CONCAT('ABC',`id`) FROM `my_table`;

which will produce something like

ABC1
ABC2
ABC3
ABC4
ABC5
..

-------------------------------------
--
Cheers,
Dmitri
http://www.1-script.com/
Loading...