Home » Other » General » Auto ID
Auto ID [message #110619] Wed, 09 March 2005 01:58 Go to next message
ys_chin
Messages: 4
Registered: March 2005
Junior Member
After performing an insert statement into the parent table (Auto increment ID generated from trigger),
how to make sure that i am getting back the correct ID in order for me to perform insertion into child table?
Re: Auto ID [message #111148 is a reply to message #110619] Mon, 14 March 2005 05:38 Go to previous messageGo to next message
Frank Naude
Messages: 4581
Registered: April 1998
Senior Member
I don't quite understand your problem, but if you are using a sequence, you can always get the current value with something like this:

SELECT seqname.currval FROM dual;


INSERT INTO parent_table VALUES (seqname.nextval, ..
INSERT INTO child_table VALUES (seqname.currval, ...


Best regards.

Frank
Re: Auto ID [message #111160 is a reply to message #110619] Mon, 14 March 2005 06:29 Go to previous messageGo to next message
ys_chin
Messages: 4
Registered: March 2005
Junior Member
Thanks for helping...

My concern is actually after insert into the parent table,
there might be someone else inserted into parent table as well,
just before i inserted data into child table

INSERT INTO parent_table VALUES (seqname.nextval, ..
INSERT INTO parent_table VALUES (seqname.nextval, ..

INSERT INTO child_table VALUES (seqname.currval (wrong value), ...

What is the common practise to avoid this happen?

Thanks.
Re: Auto ID [message #111165 is a reply to message #111160] Mon, 14 March 2005 07:00 Go to previous messageGo to next message
Frank Naude
Messages: 4581
Registered: April 1998
Senior Member
Hi,

That is not a problem. CURRVAL will only return the last NEXTVAL value for your session. You don't have to worry about the other users at all.

Best regards.

Frank
Re: Auto ID [message #111168 is a reply to message #110619] Mon, 14 March 2005 07:21 Go to previous message
ys_chin
Messages: 4
Registered: March 2005
Junior Member
Yes, you are right!

Thanks a lot.
Previous Topic: Project Management
Next Topic: The distinction between DBMS and Dabase Content?
Goto Forum:
  


Current Time: Sat Nov 23 02:45:10 CST 2024