HOW TO return last inserted row ?

Database
N/A

HOW TO return last inserted row ?

hi,

i have a table with identity column being unique primary index.

Is there a way to write a querry that will return a value of that column of my most recently inserted row?

thanks.
5 REPLIES

Re: HOW TO return last inserted row ?

Pbar,

The row with the max value for the column identity is the recently inserted row.

select * from table_name where identity_col in (sel max(identity_col) from table_name);

cheers:-)
Teradata Employee

Re: HOW TO return last inserted row ?

Hello,

With only having an IDENTITY column and no Insert/Update Date/Timestamp, you cannot get the latest inserted row.

Smilever, please note IDENTITY does not generate values in sequence.

HTH!

Regards,

Adeel

Re: HOW TO return last inserted row ?

The Teradata 12.0 release provides a new feature that enables the auto-generated key value (or all the columnds inserted row) to be returned to the application. The feature is available through the ODBC API. Usage information may be found in the "ODBC Driver for Teradata User Guide" publication.

Re: HOW TO return last inserted row ?

Adeel,

Thanks a lot for the correction.I thought IDENTITY column generates values in sequence.

Cheers:-)

Re: HOW TO return last inserted row ?

What particular feature in the ODBC API are you referring to for retrieving the IDENTITY value?