Ho to get new inserted ID from a trigger?

Discussion forum about all things Team Developer 7.x
aspurga
Lithuania
Posts: 57
Joined: 06 Mar 2017, 08:54
Location: Lithuania

Ho to get new inserted ID from a trigger?

Post by aspurga » 11 Jun 2019, 06:49

Hello,


I have a table with auto-increment column ID. After insert I need to get a new inserted ID. I can’t use Select MAX( ID ) as inserts are in multiuser environment. Tried to use a trigger with a procedure

CREATE TRIGGER SYSADM.TRG_INSERT AFTER INSERT ON SYSADM.TEST
(EXECUTE SYSADM.GETNEW_ID( new.TEST.ID ) )
FOR EACH ROW

PROCEDURE: GETNEW_ID
Parameters
Number nNew_ID
Local Variables
Actions
On Procedure Startup
On Procedure Execute
On Procedure Close
Return nNew_ID

A procedure call from TD returns nothing. What is wrong?

Arunas

H3PO4
Germany
Posts: 57
Joined: 10 Mar 2017, 07:53
Location: Rohlstorf, Germany

Re: Ho to get new inserted ID from a trigger?

Post by H3PO4 » 11 Jun 2019, 08:39

Hi Arunas,

have you tried the @AUTOINCREMENTLAST keyword?

Regards
Henning

aspurga
Lithuania
Posts: 57
Joined: 06 Mar 2017, 08:54
Location: Lithuania

Re: Ho to get new inserted ID from a trigger?

Post by aspurga » 11 Jun 2019, 09:00

I tried, but when table has dozen of thousand records it take not acceptable long time.

Regards,

Arunas

thomas.uttendorfer
Site Admin
Site Admin
Germany
Posts: 168
Joined: 05 Mar 2017, 17:19
Location: Munich Germany

Re: Ho to get new inserted ID from a trigger?

Post by thomas.uttendorfer » 11 Jun 2019, 10:40

Hi Arunas,

if time for inserting data is crucial we use GUIDs und produce them in the client.
So we have the ID even before saving the data.
Regards Thomas
Thomas Uttendorfer
[ frevel & fey ] Software-System GmbH
https://thomasuttendorfer.wordpress.com/

aspurga
Lithuania
Posts: 57
Joined: 06 Mar 2017, 08:54
Location: Lithuania

Re: Ho to get new inserted ID from a trigger?

Post by aspurga » 13 Jun 2019, 11:09

Hi Thomas,

Thanks,

Checked works fine, in my understanding it's the good idea for the new application and tables. My table has a lot records from 2003, it also has a constraints with child tables, so I have a doubt about worth of all these changes from ID to GUIDs.

Regards,

Arunas

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 0 guests