Pergunta de entrevista da empresa TechRAQ Info Solutions

How to find the last inserted id in SQL?

Resposta da entrevista

Sigiloso

15 de mai. de 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