1

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 ()
CSharp-n
  • 291
  • 2
  • 15

2 Answers2

1

Try this :

Insert into tab1 (tab1.Name) values('foo')
SELECT LAST_INSERT_ID() FROM tab1 LIMIT 1
yasseros
  • 841
  • 9
  • 16
0

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')
Purvi Barot
  • 241
  • 2
  • 9