Skip to content

ErcanOPAK.com

  • ASP.Net WebForms
  • ASP.Net MVC
  • C#
  • SQL
  • MySQL
  • PHP
  • Devexpress
  • Reportviewer
  • About
SQL

How to reset identity seed after deleting records in SQL

- 14.12.22 - ErcanOPAK

The DBCC CHECKIDENT management command is used to reset the identity counter. The command syntax is:

DBCC CHECKIDENT (table_name [, { NORESEED | { RESEED [, new_reseed_value ]}}])
[ WITH NO_INFOMSGS ]

Example:

DBCC CHECKIDENT ('[TestTable]', RESEED, 0);

IMPORTANT: The following example forces the current identity value in the AddressTypeID column in the AddressType table to a value of 10. Because the table has existing rows, the next row inserted will use 11 as the value. The new current identity value is defined for the column plus 1 (which is the column’s increment value).

USE AdventureWorks2022;
GO
DBCC CHECKIDENT ('Person.AddressType', RESEED, 10);
GO

 

Related posts:

How to add default value for Entity Framework migrations for DateTime and Bool
Unique Constraints in MS SQL Server to prevent duplications
Change Default Value for "Select Top n" and "Edit Top n" Rows in SQL Server Studio
View the Definition of a Stored Procedure in SQL
Post Views: 1

Post navigation

The Ternary Operator in C# (?:)
Differences between FirstOrDefault and SingleOrDefault in LINQ

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

January 2023
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
« Dec    

Most Viewed Posts

  • Get the First and Last Word from a String or Sentence in SQL (512)
  • Add Constraint to SQL Table to ensure email contains @ (288)
  • Get the User Name and Domain Name from an Email Address in SQL (274)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (263)
  • Find numbers with more than two decimal places in SQL (246)
  • ASPxGridView – Disable CheckBox based on condition in GridViewCommandColumn (230)
  • Confirm before process with ASPxButton in Devexpress (229)
  • How to solve “Response.Redirect cannot be called in a Page callback” for DevExpress Components (221)
  • How to make some specific word(s) Bold or Underline in ReportViewer (205)
  • Devexpress ASPxGridview Column Grouping in Code (205)

Recent Posts

  • What is the difference between ‘ref’ and ‘out’ keywords in C#
  • How to check if javascript is enabled on the client’s browser
  • How to disable ASP.Net button after click to prevent double clicking
  • What is the difference between HashSet and List in .net?
  • What is the purpose of nameof in C#?
  • What is the difference between Select and SelectMany in Linq
  • Differences between FirstOrDefault and SingleOrDefault in LINQ
  • How to reset identity seed after deleting records in SQL
  • The Ternary Operator in C# (?:)
  • The Null Conditional Operator in C# (?.)

Most Viewed Posts

  • Get the First and Last Word from a String or Sentence in SQL (512)
  • Add Constraint to SQL Table to ensure email contains @ (288)
  • Get the User Name and Domain Name from an Email Address in SQL (274)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (263)
  • Find numbers with more than two decimal places in SQL (246)

Recent Posts

  • What is the difference between ‘ref’ and ‘out’ keywords in C#
  • How to check if javascript is enabled on the client’s browser
  • How to disable ASP.Net button after click to prevent double clicking
  • What is the difference between HashSet and List in .net?
  • What is the purpose of nameof in C#?

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter

© 2023 ErcanOPAK.com

Proudly powered by WordPress | Theme: Xblog Plus by wpthemespace.com