How to get last inserted record Id in Gupta SQL Base

424 Views Asked by At

I am new to Gupta Sql Base. I would like to know how to get the last inserted record in Gupta SQL

1

There are 1 best solutions below

2
On BEST ANSWER

If you are using SYSDBSequence.NextVal to generate your Primary Key, either within the Insert stmt, or prior to the Insert , then you can retrieve it back immediately after the Insert by Selecting Where [Primary Key] = SYSDBSequence.Currval e.g. Select Name from Patient Where Patient_Id = SYSDBSequence.Currval

Alternatively, If your Primary Key column has been defined as AUTO_INCREMENT , you can select it back after the Insert using MAX( [Primary Key ] ) e.g. Select Name from Patient Where Patient_Id = (Select MAX( Patient_Id) from Patient )

Alternatively, if none of the above, then write an Insert Trigger to either return it , or to store the PK in a table so you will always have the latest PK recorded for you.

You may like to join the Gupta users forum at enter link description here or there is much archived information at enter link description here