Identity column in SQL Server

This is only for identity coloum
Create Table tblPerson
(
PersonId int Identity(1,1) Primary Key,
Name nvarchar(20)
)


Insert into tblPerson values ('Sam')
Insert into tblPerson values ('Sara')

Insert into tblPerson values ('Todd') where personid=2
select * from tblperson
Insert into tblPerson(PersonId, Name) values(2, 'John')

delete tblPerson where personid=2
SET Identity_Insert tblPerson ON --suppose we have deleted any in between the table and we try to insert the row but it can be inserted by this querry we inserted the row
SET Identity_Insert tblPerson OFF --after modification we need to again resert the identity insert..

DBCC CHECKIDENT(tblPerson, RESEED, 0)-- if we want to completely delete our table and start is agiin from the person id =1 the we should use this querry

Comments

Popular posts from this blog

Prime Number Program in C#

Fibonacci Series in C#

view in sql server