@@IDENTITY Function
@@Identity is a system function that returns the last-inserted identity value.
Note that it returns the last identity value generated in any table in the current session.
This is in contrast to the IDENT_CURRENT() function, which returns the last-inserted identity
value for a given table.
The SCOPE_IDENTITY() function is very similar to @@IDENTITY in that it also returns
the last-inserted identity value in the current session. The difference is that
SCOPE_IDENTITY() is limited to the current scope.
Example 1:
--- (a) Check Identity Before We start
SELECT @@IDENTITY AS Ident, MAX(ID) AS MaxID FROM PERSONS;
Result:
Ident MaxID
101 101
--- (b) Insert Recorts and Check @@Identity agian
INSERT INTO Persons
VALUES('HAVERTY','TIMPAT',56),
('HAVERTY','JOHNJOE',40);
SELECT @@IDENTITY AS Ident, MAX(ID) AS MaxID FROM PERSONS;
Result:
Ident MaxID
103 103
See Also
Identity Columns,
SCOPE_IDENTITY,
IDENT_CURRENT(),
SET IDENTITY_INSERT command