Microsoft SQL Server

SCOPE_IDENTITY()

Syntax#

  • SELECT SCOPE_IDENTITY();
  • SELECT SCOPE_IDENTITY() AS [SCOPE_IDENTITY];
  • SCOPE_IDENTITY()

Introduction with Simple Example

SCOPE_IDENTITY() returns the last identity value inserted into an identity column in the same scope. A scope is a module: a stored procedure, trigger, function, or batch. Therefore, two statements are in the same scope if they are in the same stored procedure, function, or batch.

INSERT INTO

([column1],[column2]) VALUES (8,9);
GO
SELECT SCOPE_IDENTITY() AS [SCOPE_IDENTITY];
GO


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow