| Author: www.DotNetVJ.com 30 Jun 2008 | Member Level: Diamond | Rating:  Points: 6 |
Hi
Create one stored procedure for the below where stored procedure should accept table name and the value to start with.
dbcc checkident (EMP, reseed, 30)
Call the stored procedure from your application code.
Reseeding the identity value:
You can reseed the indentity value, that is, to have the identity values reset or start at a new predefined value by using DBCC CHECKIDENT. For example, if I have a table named MYTABLE and I want to reseed the indentity column to 30 I would execute the following:
dbcc checkident (EMP, reseed, 30)
If you wanted to reseed the table to start with an identity of 1 with the next insert then you would reseed the table's identity to 0. The identity seed is what the value is currently at, meaning that the next value will increment the seed and use that. However, one thing to keep in mind is that if you set the identity seed below values that you currently have in the table, that you will violate the indentity column's uniqueness constraint as soon as the values start to overlap. The identity value will not just “skip” values that already exist in the table.
Check out the below link http://dotnetvj.blogspot.com/2008/01/identity-columns.html
Thanks -- Vj http://dotnetvj.blogspot.com
Thanks -- Vijaya Kadiyala http://www.DotNetVJ.com Microsoft MVP Me & My Little Techie
|
| Author: Sandesh S 30 Jun 2008 | Member Level: Gold | Rating:  Points: 2 |
use the below query to reset identity column in sql server to 1 dbcc checkident (Table_name, reseed, 1)
Regards, Sandesh Segu http://sanssql.blogspot.com http://www.orkut.co.in/Main#Community?cmm=96088888 SansSQL
|
| Author: Sriram 01 Jul 2008 | Member Level: Gold | Rating:  Points: 6 |
create table pors(proid int identity(1,1),proname varchar(50))
select * from pors insert into pors values('paste')
dbcc checkident (pors, reseed, 30)
create table pors(proid int identity(1,1),proname varchar(50))
select * from pors insert into pors values('box')
dbcc checkident (pors, reseed, 30)
set identity_insert pors off delete pors where proname='gox' insert into pors(proid,proname) values(36,'sdfds')
|