Retrieve Last Inserted Identity

To returns the last IDENTITY value produced on a connection get last Identity your Session added by your Connection if they any trigger add to any other tables it will return it

SELECT @@IDENTITY
To returns the last IDENTITY value produced on a connection and by a statement in the same scope

SELECT SCOPE_IDENTITY()
To returns the last IDENTITY value produced in a table it returns the identity value generated for a specific table in any session and any scope

SELECT IDENT_CURRENT('tablename')
To avoid the potential problems associated with adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your T SQL Statement or Stored Procedure.

Comments

Popular posts from this blog

C# Crop white space from around the image

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

The specified version string contains wildcards, which are not compatible with determinism.