Re-seed Identity Table


/ Published in: SQL
Save to your folder(s)

Re-seed identity table if rows were deleted/there are gaps in numerical order


Copy this code and paste it in your HTML
  1. DECLARE @TableName VARCHAR(255)
  2. DECLARE @MaxID INT
  3.  
  4. SET @TableName = 'Categories'
  5.  
  6. SELECT @MaxID = MAX(category_id)
  7. FROM categories
  8. DBCC CHECKIDENT(@TableName, RESEED, @MaxID)
  9. GO

URL: http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.