Many times we need to truncate a table which has an FK constraint on it. Typically we get the following error:
Cannot truncate table 'TableName' because it is being referenced by a FOREIGN KEY constraint.
The solution to the above problem is to follow the below steps :
1) Drop the constraints
2) Truncate the table
3) Recreate the constraints.
Of course, the above will only work provided the child has already been truncated.
Alternatively you can Use a DELETE without a where clause and then RESEED the identity as below:
DELETE FROM tablename
DBCC CHECKIDENT ('tablename', RESEED, 0)
0 Comment(s)