Path: news.netfront.net!zen.net.uk!dedekind.zen.co.uk!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From: Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups: comp.databases.mysql
Subject: Re: Store a process number with date
Date: Sun, 01 Feb 2015 20:57:33 -0500
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <mamlhe$5jp$1@dont-email.me>
References: <5f08282e-32aa-47a1-8ef6-75ce53cb7130@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 2 Feb 2015 01:57:02 +0000 (UTC)
Injection-Info: mx02.eternal-september.org; posting-host="3088393e34bc61b3e6a923d0c81ae1e3";
 logging-data="5753"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/XSOQBhtfw7x0KONdvJuMYV0NyqBYYdJs="
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
In-Reply-To: <5f08282e-32aa-47a1-8ef6-75ce53cb7130@googlegroups.com>
Cancel-Lock: sha1:nXvJgEDKCDaPrTs6sGHavhPKdsE=
Xref: news.netfront.net comp.databases.mysql:2376

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@attglobal.net
==================
