Truncating a T-SQL (SQL Server) table with foreign keys

Here’s a quick reminder on how to best truncate and reset primary keys on a table in Microsoft SQL Server that has foreign keys defined.

DELETE FROM [TableName] DBCC CHECKIDENT ([TableName], RESEED, [0|1])

Set the third parameter to ‘0’ when data was already in the table. If the table hasn’t been populated already use ‘1’.



Leave a Reply

Your email address will not be published. Required fields are marked *