Re: Store a process number with date

From: Jerry Stuckle <jstucklex_at_attglobal.net>
Date: Sun, 01 Feb 2015 20:57:33 -0500
Message-ID: <mamlhe$5jp$1_at_dont-email.me>


On 2/1/2015 8:22 PM, Álesson David Gomes Nunes wrote:
> Hello everybody,
>
> I'm needed auto create a process number on my aplication. So I'm using
>
> INSERT INTO mytable values (null, now());
>
> But I need a things like that 20150201xxx where xxx is a number auto incremented, the "id_" of this table, for example.
>
> Anybody have an idea that like I can make this.
>

Why do you need this? The id should only be used to identify a unique row; it shouldn't be data dependent.

But if you *must* - you have a real problem. The value you want is bigger than an INTEGER, so you'll have to use a BIGINT. Depending on your OS and the language you're using, it may or may not support BIGINT.  If not, you'll have to use a string datatype, which will make things harder.

If you *must* do this, you would have to build the string yourself. You could keep another table with a single column being the sequence number, for instance, then use that to build the key you want. Of course, to do this, you'll need to ensure you're using the INNODB engine and transactions to ensure both tables get updated correctly. This could be done in a trigger, for instance, or you could build a MySQL function to return the appropriate value.

But I would really suggest you figure out WHY you think you need such a field. It will do nothing but lead to more problems in the future.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex_at_attglobal.net
==================
Received on Mon Feb 02 2015 - 02:57:33 CET

Original text of this message