Reset Identity of a table

To reset the identity value to 0, the table should be empty or else it will error out. The faster way to do this, remove the contents of the table and reset the identity, is to use the TRUNCATE TABLE command:

TRUNCATE TABLE tablename

This only works if there are no foreign key contraints against this table’s primary key – otherwise it will fail.

Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

 

 
eXTReMe Tracker