@@IDENTITY Returns the last identity created in the same session
where as SCOPE_IDENTITY() Returns the last identity created in the same session and the same scope. See below example for better understanding
CREATE TABLE Table1
(
ID_col1 INT IDENTITY(1,1),
text_col1 VARCHAR(100)
)
GO
CREATE TABLE Table2
(
ID_col2 INT IDENTITY(5,5),
text_col2 VARCHAR(100)
)
GO
CREATE TRIGGER InsertValuesInTable1
ON Table1 AFTER INSERT AS
BEGIN
INSERT INTO Table2 (text_col2) VALUES ('some text for table 2')
INSERT INTO Table2 (text_col2) SELECT text_col1 FROM inserted
END
INSERT INTO Table1 (text_col1) VALUES ('some text for table 1')
--SEE THE DIFFERENCE HERE BY RUNNING THIS QUERY
SELECT SCOPE_IDENTITY(), @@IDENTITY