Click here to Skip to main content
Click here to Skip to main content

Reset Table Identity

By , 13 Nov 2010
 
DBCC CHECKIDENT can reset the identity value of the table.
For example, Your Table has 25 rows with 25 as last identity. If we want next record to have identity as 35, we need to run the following TSQL 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.
 
Please do let me know if you have any doubt.
 
Please provide "Vote":thumbsup: if this would be helpful.:rose:
 
Thanks,
Imdadhusen

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Sunasara Imdadhusen
Software Developer (Senior) Infostretch Ahmedabad-Gujarat
India India
Member
Aspiring for a challenging carrier wherein I can learn, grow, expand and share my existing knowledge in meaningful and coherent way.

sunaSaRa Imdadhusen
+91 99095 44184
 
AWARDS:
  1. 1st Best Asp.Net article of SEP 2010
  2. 2nd Best Asp.Net article of MAY 2011
 
Read More Articles...

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberSavalia Manoj M7 Nov '12 - 1:11 
Good one...
GeneralTo re-populate a table you can use TRUNCATE statement. It al...membertarun_j20017 Nov '10 - 19:27 
To re-populate a table you can use TRUNCATE statement. It also reset the Identity column of the table.
GeneralReason for my vote of 5 Very helpful, thank you.memberRiverama17 Nov '10 - 5:57 
Reason for my vote of 5
Very helpful, thank you.
GeneralReason for my vote of 4 Useful tip. Sometimes you need to re...memberdmjm-h16 Nov '10 - 5:01 
Reason for my vote of 4
Useful tip. Sometimes you need to re-populate a table from another and want to avoid DROP/CREATE.
GeneralIf you re start identity you need to delete all records from...memberAbdul Quader Mamun10 Nov '10 - 18:43 
If you re start identity you need to delete all records from table.
GeneralReason for my vote of 3 If table has to start with an identi...memberAbdul Quader Mamun10 Nov '10 - 18:42 
Reason for my vote of 3
If table has to start with an identity of 1 with the next insert then table should be reseeded with the identity to 0. For this, If you execute when records available in table it will throws error
GeneralIf table has to start with an identity of 1 with the next in...memberAbdul Quader Mamun10 Nov '10 - 18:41 
If table has to start with an identity of 1 with the next insert then table should be reseeded with the identity to 0. For this, If you execute when records available in table it will throws error.
General5memberDoncp15 Apr '11 - 11:21 
Very useful and concise - thanks.
 
Don

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 13 Nov 2010
Article Copyright 2010 by Sunasara Imdadhusen
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid