employer cover photo
employer logo
employer logo

TechRAQ Info Solutions

Is this your company?

TechRAQ Info Solutions interview question

How to find the last inserted id in SQL?

Interview Answer

Anonymous

May 15, 2019

There are three ways in sql server to find out the last inserted id. 1. @@Identity will give last inserted ID but the problem is it is not a scope limited. In case there is a trigger acting on the table @@Identity will give the last inserted id of the trigger. 2. scope_identity will give the last inserted ID with in the scope 3. Identity_current(table_name) will give the Last Iserted ID of the the table_name passed as parameter