Digging identity in sql server
on other day i faced problems with identity column in a table after going through several postings in the web i found following most valuable information
An IDENTITY column of tinyint datatype can go upto 255, smallint
can go upto 32767, int can go upto 2147483647 and bigint can go
upto 9223372036854775807
IDENT_CURRENT:
Returns the last identity value generated for a specified table
or view in any session and any scope.
SELECT IDENT_CURRENT ('dbo.Staging_ClassLoad') AS
Current_Identity
SELECT IDENT_CURRENT('t7');
/* Returns the last value inserted into t7.*/
@@IDENTITY :
returns the last identity value generated for any table in the
current session, across all scopes.
SELECT @@IDENTITY;
/* Returns NULL because there has been no INSERT action
up to this point in this session.*/
SCOPE_IDENTITY:
returns the last identity value generated for any table in the
current session and the current scope.
/* Returns NULL because there has been no INSERT action
up to this point in this scope in this session.*/
An IDENTITY column of tinyint datatype can go upto 255, smallint
can go upto 32767, int can go upto 2147483647 and bigint can go
upto 9223372036854775807
IDENT_CURRENT:
Returns the last identity value generated for a specified table
or view in any session and any scope.
SELECT IDENT_CURRENT ('dbo.Staging_ClassLoad') AS
Current_Identity
SELECT IDENT_CURRENT('t7');
/* Returns the last value inserted into t7.*/
@@IDENTITY :
returns the last identity value generated for any table in the
current session, across all scopes.
SELECT @@IDENTITY;
/* Returns NULL because there has been no INSERT action
up to this point in this session.*/
SCOPE_IDENTITY:
returns the last identity value generated for any table in the
current session and the current scope.
/* Returns NULL because there has been no INSERT action
up to this point in this scope in this session.*/
Comments