DBCC CHECKIDENT can reseed (reset) the identity value of the table. For example, YourTable has 25 rows with 25 as last identity. If we want next record to have identity as 35 we need to run following T SQL script in Query Analyzer.
DBCC CHECKIDENT (yourtable, reseed, 34)
If table has to start with an identity of 1 with the next insert then table should be reseeded with the identity to 0. If identity seed is set below values that currently are in table, it will violate the uniqueness constraint as soon as the values start to duplicate and will generate error.
Reference : Pinal Dave (http://blog.SQLAuthority.com)




Thanks…The article was very helpful for me…Rajeev
It should be noted that if you run DBCC CHECKIDENT (yourtable, reseed, seed_value) on a virgin table that has never had records in it, the next record added will receive an identity value of (seed_value), rather than (seed_value + 1). In other words, running DBCC CHECKIDENT (yourtable, reseed, 0) on a virgin table will result in the first record receiving an identity value of 0, not 1.
It has been suggested that running the statement a second time without the seed value will address this, but I have had mixed results with this method:
DBCC CHECKIDENT (yourtable, reseed, seed_value)
DBCC CHECKIDENT (yourtable, reseed)
Hello Ron,
This is excellent addition to original post. Thank you very much for your addition.
Kind Regards,
Pinal Dave
(http://www.SQLAuthority.com)
Hi I have tried this to set identity. I have faced some problem like:
I have a table “test” with 2 columns as id int identity 1,1 and name varchar(10)
i entered 5 records then run the query: DBCC CHECKIDENT (test, reseed, 34)
and then inserted 2 rows, it works but again I run this query
DBCC CHECKIDENT (test, reseed, 3)
then the next value in id column is 4 which is against the rule of identity. identity means unique. please correct me if i am wrong.
Can we generate alphanumeric values in sequence no in identical column?
Like I want my registeration for Gurgoan city should follow like:-
ggn1
ggn2
ggn3
.
.
.
.
.
.
ggnn
Thanks
[...] will have to get the maximum identity before you truncate and reset it to that maximum identity. SQL SERVER – DBCC RESEED Table Identity Value – Reset Table Identity . If you are not using identity or do not have use for identity you do not have to [...]
Does DBCC RESEED works with replicated databases? Can I change the identity value on a subscription database?
Hi mithilesh kumar,
Identity columns does not stand for uniqueness,
Unless you don’t define identity column as part of Primary Key.
How do I delete the content of a table or whole database???
We experience a strange problem. Identity field of a table is set to [1,1] by generating script. Every time, when we drop the whole database, and then re-create it by running script in SQL Server 2008 Management Studio, and then insert a record into that table programmatically (C# code), SQL Server set identity field record of that first record to 0 instead of 1!
Then we also programmatically delete all records from that table and then execute
DBCC CHECKIDENT(‘” + targetTableName + “‘, RESEED, 0)
Next time, the same C# function inserts records correctly, with identity field starting from 1 as expected.
So, again, identity field does not want to behave correctly if database was just created by script. After inserting a record and deleting it, everything works fine.
Is it SQL Server 2008 bug? Any idea on possible workaround?
MSDN is a good reference, but you are THE reference, thank god you exist !
Best regards,
Leo Espejo
Thanks to Dave for the OP and to Ron Moses for the virgin table observation. I had been troubleshooting this for some time. Glad to have found this post.
Thanks again,
Nick
I have a table designed by a FORMER employee. There was no primary key created. In the table there are 7500 some records. The values started @ 1 through 2145, then 1600 columns are null. Then the index begins @ some random number and continues ASC. Is there a way for me to just reset the FamilyFriendSurveyID column in the entire table?, I need to now make this column be a primary key for the table, can this be done to auto increment starting @ 1? Thank you in advance for your help!!!
Hello have a table in my database with value like
AAABBB<
1111<
1222<
1333<
2444<
2555<
2666<
3777<
3888<
3999<
i want an sql query that display distinct value from column AAA and its MAX value from column BBB
as shown below. Thanks in advance for your help!!!
1333<
2666<
3999<
Hi,
please let me know what will be the maximum seed value for a table which is of bigint. I would also helpfull if i get to know what to do if we exceed the seed value for a bigint field in a table
Excellent article.. reliable as always and saved me a lot of time! Thanks.
Vladimir
if ur table it’s new u must use:
DBCC CHECKIDENT (yourtable, reseed, seed_value)
but if u just delete that table u can use:
DBCC CHECKIDENT (yourtable, reseed, 0)
CYA
I was dropping and recreating tables for my unit (integration) tests and came across this reseed problem for virgin tables. My (ugly) fix was to 1) insert row into the table 2) delete all rows 3) reseed 4) insert (again) into the table. This way I could know for sure what id the inserted row got.
[...] SQL SERVER – DBCC RESEED Table Identity Value – Reset Table Identity [...]
Charl,
Please delete content of a table by issuing any of the following SQL statement:
DELETE FROM Table_Name;
TRUNCATE TABLE Table_Name;
Replace Table_Name with the actual table whose content you want to delete.
Deleting a whole database means that you will need some privileges, that is database admin privileges or database owner privileges.
To delete a database, issue the following SQL statement:
DROP DATABASE Database_Name;
Regards,
Chris Musasizi
Thanks!! I had this problem always, it was so helpful!!
:)
What I wanted, short and simple described.
Thanks!
How can we reseed or use the DBCC CheckIdent on a table with the prefix of a link server name. I get a syntax error when prefixing the table location with a link server name, e.g. DBCC CHECKIDENT ([LinkServerName].DBName.dbo.[tableName], RESEED, 0)