I recently added Items to an ID and the the table got messed up in the transfer process so I deleted the Items from the table. Upon reentering the data instead of the ID starting at one it now starts at 332. I would like to have the table start at one instead of 332. I've removed the data from the data so it's clear. How do I reset the ID to one. Thanks and sorry if this on here somewhere I wasn't sure how to search for this.
+2
A:
Assuming MSSQL:
DBCC CHECKIDENT('MyTable', RESEED, 0) -- One less than next ID to allocate
If you want to remove the data too you can use
TRUNCATE TABLE MyTable
but you cannot use TRUNCATE TABLE on a table referenced by a Foreign Key, or if the table is part of an indexed view, and unlike DELETE MyTable any trigger(s) on the table won't be activated.
Kristen
2009-02-26 23:38:53
A:
Set the starting identity value to 1
DBCC CHECKIDENT (tableName, RESEED, 1)
Andrew Robinson
2009-02-26 23:39:31
Compact and repair is quite sufficient to reset an autonumber, however, if someone is concerned about the value of an autonumber, it is quite likely that they have missed the point and will next want it to be sequential, and this is unlikely over the life of a table.
Remou
2009-02-26 23:52:25