SQL Flow Field Guide

SCOPE_IDENTITY

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

reads prior-statement state

What changes

Input
last identity generated in the current scope
Output or change
numeric value
Return type
numeric(38,0)

Syntax at a glance

SCOPE_IDENTITY()

Work example

Read the last identity value generated in the current scope after an insert.

Capture it immediately in the same scope and use OUTPUT when a statement returns several generated keys.

Check your work SCOPE_IDENTITY is safer than @@IDENTITY when a trigger inserts into another identity table.

Practice SQL

Open in SQL Flow
SELECT SCOPE_IDENTITY() AS last_identity_in_scope;

Open Microsoft Learn for full syntax, permissions, and details for your version.