Autogenerated number
Hi:
How could I get the autogenerated number when a record is inserted?
[80 byte] By [
Stephen] at [2007-11-9 18:50:41]

# 1 Re: Autogenerated number
If you're running UDB under 6.x you're outta luck, as far as I remember. UDB
7.x has autonumber (IDENTITY) columns, but I'm not too sure about that.
As to how you actually get them, well, you need to hack it. One of our
clients implemented a terribly hacky VB object that uses the MTS SPM to read
off and cache a database field in a sort of atomic fashion. The component is
called for a new key (or range of keys) using a certain key value (i.e, the
name of the table), reads the field, adds the requested range and writes it
back for the next request. Needless to say, this is extremely expensive. But
there's no other way.
I'll tell you what I tell everyone: If you're using Microsoft products
(NT/W2K, VB, VC++, OLEDB/ADO, MTS/COM+, MSMQ, etc), get rid of UDB if you
can. Even Oracle is better, and I'd go with SQL Server 2000 as the ideal.
DB2/UDB is, for all practical purposes, useless on the NT platform.
Especially as a backend for the classic IIS-MTS physical two-tier
distributed app. MTS and UDB just do not get along.
.. . . . . . . . . . . . . . . . . . . . . .
Klaus H. Probst, MVP
http://www.vbbox.com/
http://www.mvps.org/ccrp/
Please post/reply to the newsgroup(s)
"Stephen" <sman198@hotmail.com> wrote in message
news:3a6f06b3$1@news.dev-archive.com...
>
> Hi:
>
> How could I get the autogenerated number when a record is inserted?
# 2 Re: Autogenerated number
"Stephen" <sman198@hotmail.com> wrote:
>
>Hi:
>
>How could I get the autogenerated number when a record is inserted?
You might look at the function generate_unique. It doesn't exactly generate
a number, but is supposed to generate a unique key value.
# 4 Re: Autogenerated number
Within the same transaction(Caveat: Autocommit in CLP!) you can use the
identity_val_local() function.
It is described in the releae notes
Example:
CREATE TABLE T(id INT GENERATED ALWAYS AS IDENTITY, c1 INT);
INSERT INTO T(c1) VALUES(5);
SELECT identity_val_local() FROM SYSIBM.SYSDUMMY1;
Cheers
Serge
# 5 Re: Autogenerated number
You have to do it via a stored procedure in V5, don't believe this capability
has been added to V7.
Go to the DB2 newsgroups - this is a very common DB2 question.
"Stephen" <sman198@hotmail.com> wrote:
>
>Hi:
>
>How could I get the autogenerated number when a record is inserted?
Dave at 2007-11-12 0:10:35 >
