Always get the current inserted ID at the time of writing the stored procedure with @ @IDENTITY
But today when using @ @IDENTITY is involved in the current data insertion will have an INSERT trigger occurs, found with the actual inserted ID value is not on, online query, with scope_identity () just fine
Select scope_identity ()
Returns the value of the identity column of the last row of the data table above operation;
Returns the last identity value in the identity column inserted into the same scope. A scope is a module-a stored procedure, trigger, function, or batch. Therefore, if two statements are in the same stored procedure, function, or batch, they are in the same scope.
SELECT @ @IDENTITY
Returns the value of the identity column of the last row of the last data table above operation;
To create a table:
Create Table int Identity (1,1notnullvarchar(notnull)
Insert data:
Insert into Values (' who am I 'Selectscope_identity()
Stored procedures:
CREATE PROCEDURE [dbo]. [sp_user] (@F_NameintasbeginTran insertinto_t_user Insertinto values(@F_Name)Selectscope_ IDENTITY()
SQL Server SELECT @ @IDENTITY pits encountered