Skip to content

IDENTITY column

It is nothing but auto increment of the column

syntax:

1
2
3
4
5
Create table emp
(
  empId int identity(1,1) ,
  empName varchar(50)
)

How to retrive last identity column values

1.Scope_identity:

Returns the last identity value inserted into an identity column in 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.

1
SCOPE_IDENTITY() 

@@Identity:

Is a system function that returns the last-inserted identity value in any table in current session

1
@@identity

ident_current:

returns the last identity value generated for a specific table

1
select ident_current('tablename')