Tuesday, August 21, 2007

Can't truncate table with Foreign Key

When trying to truncate a table that is referenced by a Foreign Key I always get this message, even if the table referencing the primary table is empty.

Server: Msg 4712, Level 16, State 1, Line 1
Cannot truncate table 'actTouches' because it is being referenced by a FOREIGN KEY constraint.

To get around this problem I simply delete all rows from the table then re seed the identity column with 1.

Delete From [table]
DBCC CheckIdent ([table], RESEED, 1)

No comments:

Post a Comment

Please leave your thoughts, I love hearing what you got out of the post. Spam comments will be removed.