SCOPE_IDENTITY

SCOPE_IDENTITY#

Returns the last identity value generated by an INSERT in the current session and scope, captured at INSERT time. Returns NULL when no identity value has been captured — for example, before any INSERT in the session, or when the identity value was generated by a source other than SQL Server (capture is SQL-Server-only).

Syntax#

SCOPE_IDENTITY ( )

Return types#

decimal(28,0)

Remarks#

Querona has no triggers, so SCOPE_IDENTITY() and @@IDENTITY are equivalent — both read the same captured value.

Example#

INSERT INTO dbo.Product (Code) VALUES ('WIDGET-1');
SELECT SCOPE_IDENTITY() AS LastId;

See Also#