Loading ...

Difference between Identity() and @@identity in sql server?

 /5
0 (0votes)


IDENTITY (Property)

It Creates an identity column in a table. This property is used with the CREATE TABLE and ALTER TABLE Transact-SQL statements.

Syntax
IDENTITY [ ( seed , increment ) ]
Example
create table Mytable
(
Identity_Id int identity(1001,1),name varchar(50),city varchar(50)
)


@@IDENTITY :-

Returns the last-inserted identity value.

Syntax
SELECT @@IDENTITY AS IDs

example
select @@identity  from Mytable

 

Comments (no comments yet)

Top Posts