Posted By

CDIDevs on 12/31/09


Tagged

sql seed identity reseed


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

g8rpal
Tyster


Re-seed Identity Table


 / Published in: SQL
 

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

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

  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

Report this snippet  

You need to login to post a comment.