Tuesday, February 12, 2013

Resetting table schema Using DBCC

DBCC CHECKIDENT ('table_name', RESEED, newReseedValue)

No need to drop and create or truncate table to reset its identity.

The current identity value is set to the newReseedValue. If no rows have been inserted to the table since it was created, the first row inserted after executing DBCC CHECKIDENT will use newReseedValue as the identity. Otherwise, the next row inserted will use newReseedValue + 1. If the value of newReseedValue is less than the maximum value in the identity column, error message 2627 will be generated on subsequent references to the table.

delete from timesheet
delete from timesheetitem

dbcc checkident('timesheet',reseed,0)
dbcc checkident('timesheetitem',reseed,0)

No comments:

Post a Comment