Click here to Skip to main content
15,867,453 members
Articles / Programming Languages / SQL
Tip/Trick

Reset Table Identity

Rate me:
Please Sign up or sign in to vote.
4.95/5 (20 votes)
13 Nov 2010CPOL 35.7K   8   17
SQL SERVER – DBCC RESEED Table Identity Value – Reset Table Identity
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.

SQL
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)


Written By
Technical Lead 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. 2nd Best Mobile Article of January 2015
  2. 3rd Best Web Dev Article of May 2014
  3. 2nd Best Asp.Net article of MAY 2011
  4. 1st Best Asp.Net article of SEP 2010


Read More Articles...

Comments and Discussions

 
GeneralMy vote of 5 Pin
Savalia Manoj M7-Nov-12 1:11
Savalia Manoj M7-Nov-12 1:11 
GeneralRe: My vote of 5 Pin
Sunasara Imdadhusen22-Apr-14 4:00
professionalSunasara Imdadhusen22-Apr-14 4:00 
GeneralTo re-populate a table you can use TRUNCATE statement. It al... Pin
tarun_j20017-Nov-10 19:27
tarun_j20017-Nov-10 19:27 
GeneralRe: To re-populate a table you can use TRUNCATE statement. It al... Pin
Sunasara Imdadhusen22-Apr-14 4:00
professionalSunasara Imdadhusen22-Apr-14 4:00 
GeneralReason for my vote of 5 Very helpful, thank you. Pin
Riverama17-Nov-10 5:57
professionalRiverama17-Nov-10 5:57 
GeneralRe: Reason for my vote of 5Very helpful, thank you. Pin
Sunasara Imdadhusen22-Apr-14 4:01
professionalSunasara Imdadhusen22-Apr-14 4:01 
GeneralReason for my vote of 4 Useful tip. Sometimes you need to re... Pin
dmjm-h16-Nov-10 5:01
dmjm-h16-Nov-10 5:01 
GeneralRe: Reason for my vote of 4Useful tip. Sometimes you need to re... Pin
Sunasara Imdadhusen22-Apr-14 4:01
professionalSunasara Imdadhusen22-Apr-14 4:01 
GeneralIf you re start identity you need to delete all records from... Pin
Abdul Quader Mamun10-Nov-10 18:43
Abdul Quader Mamun10-Nov-10 18:43 
GeneralRe: If you re start identity you need to delete all records from... Pin
Sunasara Imdadhusen22-Apr-14 4:01
professionalSunasara Imdadhusen22-Apr-14 4:01 
GeneralReason for my vote of 3 If table has to start with an identi... Pin
Abdul Quader Mamun10-Nov-10 18:42
Abdul Quader Mamun10-Nov-10 18:42 
GeneralRe: Reason for my vote of 3If table has to start with an identi... Pin
Sunasara Imdadhusen22-Apr-14 4:02
professionalSunasara Imdadhusen22-Apr-14 4:02 
GeneralIf table has to start with an identity of 1 with the next in... Pin
Abdul Quader Mamun10-Nov-10 18:41
Abdul Quader Mamun10-Nov-10 18:41 
GeneralRe: If table has to start with an identity of 1 with the next in... Pin
Sunasara Imdadhusen22-Apr-14 4:02
professionalSunasara Imdadhusen22-Apr-14 4:02 
General5 Pin
Doncp15-Apr-11 11:21
Doncp15-Apr-11 11:21 
GeneralRe: 5 Pin
Sunasara Imdadhusen22-Apr-14 4:02
professionalSunasara Imdadhusen22-Apr-14 4:02 

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

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