How can I clear a table and reset the identity back to 0?

A. If there are no foreign keys on the table then a simple TRUNCATE TABLE <tbl> will do the trick.

If there are foreign keys then first delete all rows - DELETE <tbl>

Then reset the identity :-

Under 7.0 - DBCC CHECKIDENT(<tbl>,RESEED,0)

Under 6.5 - DBCC CHECKIDENT(<tbl>)


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish