24 January 2014

How to Add an Identity on Column in SQL SERVER

        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 student(S_id int identity(20140,1),Student_name varchar(30), Age int) 
 
(or)
 
create table student(S_id int identity(1,1),Student_name varchar(30), Age int) 
 

Step2:- Insert values

insert into student (Student_name,Age)values('jc.adi',22)
insert into student (Student_name,Age)values('pavan',21)
insert into student (Student_name,Age)values('madhan',15)
 
Output:
 
select * from student
 

No comments:

Post a Comment