This is a discussion on Custom AutoIncrement Field within the MySQL Database forums, part of the Database Forums category; How can I acomplish that? I want a field in my table to autoincrement like 'CHD0001', 'CHD0002', 'CHD0003' thanks!...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Fabio wrote:
> How can I acomplish that? > > I want a field in my table to autoincrement like 'CHD0001', 'CHD0002', > 'CHD0003' > > thanks! Why does the CHD prefix need to be there? Will it ever change? If not it's unnecessary. It can be generated when you query the column or with a view. If yes, it should be a separate column. |
|
|||
|
On Fri, 18 Apr 2008 11:31:54 -0700 (PDT), Fabio wrote:
> How can I acomplish that? > > I want a field in my table to autoincrement like 'CHD0001', 'CHD0002', > 'CHD0003' Can't do it straight. Can CONCAT('CHD', CAST(my_id as CHAR)) on select though, where my_id is your autoincrement, zerofill int(5) column. -- 76. If the hero runs up to my roof, I will not run up after him and struggle with him in an attempt to push him over the edge. I will also not engage him at the edge of a cliff. (In the middle of a rope-bridge over a river of molten lava is not even worth considering.) --Evil Overlord List |
|
|||
|
Chuck:
> Fabio wrote: > > > > I want a field in my table to autoincrement like 'CHD0001', 'CHD0002', > > 'CHD0003' > Why does the CHD prefix need to be there? Will it ever change? > > If not it's unnecessary. It can be generated when you query the column > or with a view. If CHD is there for presentational purposes only, I would prefer putting it into the presentation (or logic) layer instead of using the database to do that. -- Erick |