Tuesday, 15 May 2012

How to use @@Identity or IDENTITY ?

Syntax
IDENTITY [ ( seed , increment ) ]

Here,

 seed :-  this is for you starting point of number.Means from which number you want to start table data increment (e'g  1,2, -1 ,0 ,100,1001  etc)



increment :-   You can set increment value as per you want (1,2,3...) how much difference you want between two numbers


Note : Identity column 'i' must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, and constrained to be nonnullable.



step 1 :   Create table in database

create table #CheckIdentity(i Int Identity,j Int)

step 2 : Insert Values in that database

insert #CheckIdentity select 1

step 3:  Display Values from table

select * from #CheckIdentity

Output :

---------
I        J
----------
1       1
2       1
3       1


Reference :  http://www.simple-talk.com/sql/t-sql-programming/identity-columns/

Link help you lot

No comments:

Post a Comment