After the insert statement is run, run select @ identity to obtain the automatically generated ID.
Select scope_identity () as ID is recommended for SQL Server.
Because @ identity
Similar ident_current ('table ')
Ident_currentReturns the final generated id value for any session and specific table in any scope. Ident_current is not restricted by the scope and session, but by the specified table. Ident_current returns the value generated for a specific table in any session and scope.
@ IdentityReturns the last generated id value for any table in all scopes of the current session.
Scope_identityReturns the last generated id value for the current session and any table in the current scope.
Scope_identity and @ identity return the last id value generated in any table in the current session. However, scope_identity only returns the value inserted into the current scope; @ identity is not limited to a specific scope.