How to Add an Identity on Column in SQL SERVER 2008

By
If we want to have a column where value should inserted automatically in incremented order, we can apply  Identity on that column.By default we can not insert value manually in Identity column.
SYNTAX:-
Identity (<seed> < Incremented >)
There are some steps to know about identity column. which are given below:-
Step1:- Create the table and add an identity  on the column.
create table emp3(eid int identity(0816113042,1),ename varchar(30), eage int)

Step2:-  Add an identity on column in existing table.
  • we can add identity column on the table,if an identity column already exist then we use following command.
alter table emp3 drop column eid 
   alter table emp3 add eid int identity(10,1)


  • we can apply identity constraint on the column when table is already created.


  • ALTER TABLE emp ADD ToBeIdentity INT IDENTITY(1,1)

    Step3:-   Insert valueS manually on identity column.
    set identity_insert emp3 on 
                --or
     set identity_insert emp3 off 
    
    insert into emp3 (ename,eage)values('ram',23)
    insert into emp3 (ename,eage)values('rajesh',25)  
    

    See it:-

    Step4:- We can also apply identity constraint on column without SQL Commands.
    first click eid column -> click Identity Specification-> now set is identity to YES .Which is shown  below:-
    see it:-

    For More:-

    1. Ms Sql server
    2. Add Identity Column
    3. Delete and Truncate statement
    4. Stored Procedure and Function
    5. Collections
    6. Take Print receipt in Windows Form Application
    I hope this is helpful for you.
    To Get the Latest  Free Updates Subscribe
    click the below for download whole commands.
                DOWNLOAD

    0 comments:

    Post a Comment

    Powered by Blogger.