Identity in SQL Server – SQL Server Tutorial

IDENTITY:–    

  • It is used to generate serial numbers for a column in a table mostly for a primary keys.

Syntax :- identity (seed,incr)

                       Seed ->Starting value.

                        Incr -> increment by value

  • Both seed,incr are optional.
  • If you don’t mention the seed ,incr then the default value is (1,1).

Example :- Create table cust

(cid int identity(100,1),

Cname varchar (20))

Insert into cust (cname)

Values (‘a’)

Select * from cust

     cid              cname

    100                  a

    101                  b

    102                  c

Leave a Reply

Your email address will not be published. Required fields are marked *