views:

32

answers:

1

whether the 'identity' used in sql server has been used twice inside same table.

ex: i need to insert some set of records with the identity column starting from 0,1,2....

and when i insert some another set of records again the identity must start with 0,1,2..

is there is any possiblity to achieve that using the identity seed.

A: 

You can use dbcc checkident to reset the identity seed, like:

if object_id('IdentityTest') is not null
    drop table IdentityTest
create table IdentityTest (id int identity, name varchar(30))
go
insert into IdentityTest (name) values ('Jeff')
insert into IdentityTest (name) values ('Joel')
DBCC CHECKIDENT ('IdentityTest', RESEED, 0)
insert into IdentityTest (name) values ('Julia')
insert into IdentityTest (name) values ('Christine')
go
select * from IdentityTest 

This prints:

1    Jeff
2    Joel
1    Julia
2    Christine
Andomar