Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8720

Re: How to FInd Last Iserted Row Id in Hana

$
0
0

Hi Vimal,

 

This might be naive, but what's wrong with

 

SELECT MAX(MY_ID) FROM MY_TABLE

 

If your ID is meant to always (auto) increment, then it will find you the last inserted row - or better the row with the highest ID...

 

Please not that HANA doesn't have an "auto-increment" feature for primary keys. What you would have to do is create a SEQUENCE (http://help.sap.com/saphelp_hanaplatform/helpdata/en/20/d509277519101489029c064d468c5d/content.htm) and then use MY_SEQUENCE.NEXTVAL to get the next value. You could use MY_SEQUENCE.CURVAL to get the current value, but depending on what you make part of one DB transaction and how you actually serialize (Lars made a very good comment about that further up in the thread - the last number you pull is not necessarily the last row you store, only when your transaction logic enforces SERIALIZABLE, which cripples the DB's features) the current value of the sequence is not the ID of the row that was inserted last.

 

--juergen


Viewing all articles
Browse latest Browse all 8720

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>