SQL Flow Field Guide

@@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 session (any scope, includes triggers)
Output or change
numeric value
Return type
numeric(38,0)

Syntax at a glance

@@IDENTITY

Work example

Read the last identity generated in the current session across scopes.

Read state in the intended scope and immediately after the statement it describes. Treat host values as untrusted.

Check your work Use SCOPE_IDENTITY or OUTPUT because a trigger can change this value.

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