Custom AutoIncrement Field

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!...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008
Fabio
 
Posts: n/a
Default Custom AutoIncrement Field

How can I acomplish that?

I want a field in my table to autoincrement like 'CHD0001', 'CHD0002',
'CHD0003'

thanks!
Reply With Quote
  #2 (permalink)  
Old 04-18-2008
Chuck
 
Posts: n/a
Default Re: Custom AutoIncrement Field

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.
Reply With Quote
  #3 (permalink)  
Old 04-18-2008
Peter H. Coffin
 
Posts: n/a
Default Re: Custom AutoIncrement Field

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
Reply With Quote
  #4 (permalink)  
Old 04-18-2008
Erick T. Barkhuis
 
Posts: n/a
Default Re: Custom AutoIncrement Field

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:30 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0