Get the last inserted row ID (HFSQL)

504 Views Asked by At

I need to get the Id(Auto Incremented) created for an inserted Row

How i can do that the documentation mentioned LAST_INSERT_ID but i don't know how to use it , i tried this but it does not work :

Insert into tab1 (tab1.Name) values('foo')
SELECT LAST_INSERT_ID ()
2

There are 2 best solutions below

0
yasseros On BEST ANSWER

Try this :

Insert into tab1 (tab1.Name) values('foo')
SELECT LAST_INSERT_ID() FROM tab1 LIMIT 1
0
Purvi Barot On

Try this:

You can use:

SELECT IDENT_CURRENT('tablename')

to access the latest identity for a particular table.

For Example:

 INSERT INTO YourTable(columns....) VALUES(..........)
 SELECT IDENT_CURRENT('YourTable')