Re: MySQL Auto PK

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 05 Jan 2005 18:11:23 -0500, John Holmes
<holmes072000@xxxxxxxxxxx> wrote:
> OOzy Pal wrote:
> > Is it possible to have mysql at an ID as 20050105-1 as
> > (YYYYMMDD-1), -2, etc.
> 
> automatically? No. But you can always just use
> 
> SELECT CONCAT(date_column,'-',pk_column) AS fixed_id ...
> 
> if you _really_ need something like this. Or just join them together in
> PHP.

I think the only downside to that solution is that the primary key
will continue to increment regardless of the day, and I think the
original poster wanted:

20050105-1
20050105-2
20050106-1
...etc.

This would be a great place for a stored procedure, but I don't know
if I can recommend running MySQL 5 to you.  The most platform-safe way
I can think of is to get a count(*) of the number of rows with today's
date, add 1 to it, and stick that number on the end of the string
you've created to insert into a varchar field.  It's an extra query
per insert, but it'd do the job.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux