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

Reset Table Identity

By , 13 Nov 2010
Rate this:
Please Sign up or sign in to vote.
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"Thumbs Up | :thumbsup: if this would be helpful.Rose | [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
Aspiring for a challenging carrier wherein I can learn, grow, expand and share my existing knowledge in meaningful and coherent way.

sunaSaRa Imdadhusen
 
AWARDS:
  1. 1st Best Asp.Net article of SEP 2010
  2. 2nd Best Asp.Net article of MAY 2011
 
Read More Articles...
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralMy vote of 5 PinmemberSavalia Manoj M7-Nov-12 1:11 
GeneralTo re-populate a table you can use TRUNCATE statement. It al... Pinmembertarun_j20017-Nov-10 19:27 
GeneralReason for my vote of 5 Very helpful, thank you. PinmemberRiverama17-Nov-10 5:57 
GeneralReason for my vote of 4 Useful tip. Sometimes you need to re... Pinmemberdmjm-h16-Nov-10 5:01 
GeneralIf you re start identity you need to delete all records from... PinmemberAbdul Quader Mamun10-Nov-10 18:43 
GeneralReason for my vote of 3 If table has to start with an identi... PinmemberAbdul Quader Mamun10-Nov-10 18:42 
GeneralIf table has to start with an identity of 1 with the next in... PinmemberAbdul Quader Mamun10-Nov-10 18:41 
General5 PinmemberDoncp15-Apr-11 11:21 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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