473,770 Members | 7,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Identity OR sequence which is better

Hello,

I would like to know Identity OR sequence which is better?.

My requirement is simple. I have a parent table with ID (generated or
from sequence) and I want that ID after inserting parent record so
that I could use it for Child table(S).

I read in on the the thread ibm is planning to deprecate
identity_val_lo cal() function in future. Appreciate the DB2 experts
advice.

Thanks,
Srini.
Nov 12 '05 #1
3 8590
Either of them have their place.
If the key you need is local to a single table and you don't need
explicit control over it then IDENTITY gives you a few benefits.
E.g. IDENTITY can be generated by LOAD, sequences surrently cannot.

One of the few drawbacks of identity today is that you cannot switch it
OFF which can be a pain for IMPORT. This however will be addressed in
DB2 Stinger.

identity_val_lo cal() shudl be deprecated because:
SELECT FROM INSERT in DB2 V8.1 FP4 does a much better job in retrieving
generated values (not only identity) in a set oriented fashion.
So instead of doing:
INSERT INTO parent(pk, c1) VALUES(DEFAULT, 5);
INSERT INTO child (pk, fk) VALUES(DEFAULT, identity_val_lo cal());

you can now say:
SELECT pk INTO :pk
FROM NEW TABLE(INSERT INTO parent(pk, c1) VALUES(DEFAULT, 5);
INSERT INTO child (pk, fk) VALUES(DEFAULT, :pk);

Or even:
WITH parent AS (SELECT pk
FROM NEW TABLE(INSERT INTO parent(pk, c1)
VALUES(DEFAULT, 5))
SELECT fk INTO :parent
FROM NEW TABLE(INSERT INTO child(fk)
SELECT pk FROM parent);

One statement :-)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
Hi Serge,
Thank you very much for your help.
I have learned something new which is good.
I understand i have a better control with SEQUENCE than IDENTITY.

Question -1
-----------
identity_val_lo cal() SHOULD be deprecated or WILL be deprecated or
BOTH?

Question -2
-----------
Will IDENTITY work fine with Concurrent INSERTS.
For Example, We have two tables that are NOT related in any way.

TABLE_A has ID (GENERATED AS IDENTITY)
TABLE_B has ID (GENERATED AS IDENTITY)

USER-A will INSERT a record in TABLE_A
USER-B will INSERT a record in TABLE_B

Now if USER-A calls identity_val_lo cal() function, How he can be sure
he is getting ID for TABLE_A and not TABLE_B. Both the user will have
their own Transaction.

Thanks for your time,
Srini.

Serge Rielau <sr*****@ca.e ye-be-em.com> wrote in message news:<c0******* ***@hanover.tor olab.ibm.com>.. .
Either of them have their place.
If the key you need is local to a single table and you don't need
explicit control over it then IDENTITY gives you a few benefits.
E.g. IDENTITY can be generated by LOAD, sequences surrently cannot.

One of the few drawbacks of identity today is that you cannot switch it
OFF which can be a pain for IMPORT. This however will be addressed in
DB2 Stinger.

identity_val_lo cal() shudl be deprecated because:
SELECT FROM INSERT in DB2 V8.1 FP4 does a much better job in retrieving
generated values (not only identity) in a set oriented fashion.
So instead of doing:
INSERT INTO parent(pk, c1) VALUES(DEFAULT, 5);
INSERT INTO child (pk, fk) VALUES(DEFAULT, identity_val_lo cal());

you can now say:
SELECT pk INTO :pk
FROM NEW TABLE(INSERT INTO parent(pk, c1) VALUES(DEFAULT, 5);
INSERT INTO child (pk, fk) VALUES(DEFAULT, :pk);

Or even:
WITH parent AS (SELECT pk
FROM NEW TABLE(INSERT INTO parent(pk, c1)
VALUES(DEFAULT, 5))
SELECT fk INTO :parent
FROM NEW TABLE(INSERT INTO child(fk)
SELECT pk FROM parent);

One statement :-)

Cheers
Serge

Nov 12 '05 #3
Srini,

Deprecation is a very fuzzy word. E.g. LONAG VARCHAR and LONG VARGRAPHIC
are deprecated. You can see that from the fact that none of the new
features coming into DB2 support these old types.
Nonetheless neither support nor documentation has been withdrawn.

identity_val_lo cal() was from the very beginning and consciously placed
into a small box (single row insert with values).
You will not see this function being extended and it is also very
unlikely you will see an identity_val_gl obal() or so...

Will IBM formally pull support on this function at some point? I don't
know. It's to small a fish to worry about, IMHO.
If that happens there will be ample warning though.

W.r.t. concurrency.
identity_val_lo cal() is local to the connection. IDENTITY generation in
another connection (whether the same or different table) will not affect
its value.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
8202
by: DBA | last post by:
I have an identity field on a table in SQL Server. The identity seed is 1 and the identity increment is 1. If I remove a record from this table, the identity sequence is broken. For example: Table contents prior to record delete: Fname(varchar), Lname (varchar), row_id (identity) -------------------------------------------------- Smith, Jane, 1 Smith, Tom, 2 Jones, Mark 3
1
2581
by: Ken | last post by:
Need help on the Auto Number or Identity Seed on the Oracle Database I got an Access database that need to be converted to Oracle 9i. Somehow the Trigger we created to simulate the "AUTO NUMBER" on Access could not create the sequence number as soon as the value has been inserted. The sequence number can only be created after we go to the second line. Please see the trigger below. Is there anyway we could create a trigger that could...
4
9630
by: UDBDBA | last post by:
Hi: we have column with GENERATED ALWAYS AS DEFAULT. So, we can insert into this column manually and also let db2 generate a value for this column. Given a scenario, how can i find the NEXTVAL for this identity column? We can do "VALUED NEXTVAL FOR SEQUENCE", but for identity how can it be done?
41
3164
by: pb648174 | last post by:
In a multi-user environment, I would like to get a list of Ids generated, similar to: declare @LastId int select @LastId = Max(Id) From TableMania INSERT INTO TableMania (ColumnA, ColumnB) SELECT ColumnA, ColumnB From OtherTable Where ColumnC > 15 --get entries just added
4
7291
by: shorti | last post by:
Can anyone explain in greater (and more comprehensive) detail what the RESTART option does in the ALTER TABLE table ALTER COLUMN statement. This is the description in Info Center: RESTART or RESTART WITH numeric-constant Resets the state of the sequence associated with the identity column. If WITH numeric-constant is not specified, the sequence for the identity column is restarted at the value that was specified, either implicitly or...
5
32037
by: Veeru71 | last post by:
Given a table with an identity column (GENERATED BY DEFAULT AS IDENTITY), is there any way to get the last generated value by DB2 for the identity column? I can't use identity_val_local() as the INSERTS are happening in a different session. Eg, We have the following table....
15
3536
by: gunnar.sigurjonsson | last post by:
I´m having some problem retrieving identity value from my newly inserted row into a view. I have two tables T1 and T2 which I define as following CREATE TABLE T1 ( id BIGINT GENERATED ALWAYS AS IDENTITY ( START WITH 1
0
3034
by: Frank Swarbrick | last post by:
So we're trying to decide if it's better to use IDENTITY columns or sequences to create a surrogate key as the primary key for our tables. I kind of like the identity column, because it's more 'tightly integrated' in to the table. With a sequence you have to make sure that each application that inserts records uses the same sequence. (Probably not likely that it wouldn't, but...) One thing where it seems like a SEQUENCE would be...
11
2699
by: stegze | last post by:
Hi All, I have a problem with a DB2 server of my customer. It is a Debian Linux running DB2 Express-C. I have an IDENTITY field as PK in a table and I use this value as FK in another table. Two weeks ago the FK values got corrupted or mixed up somehow. I also got some warnings about system temporary table spaces so I created a 16K page size system temporary table space to be sure. All seemed to be okay until today. Something happened an...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.