Site icon Database Tutorials

Cannot truncate table because it is being referenced by a FOREIGN KEY constraint.

 

ERROR MESAGGE:

“Cannot truncate table because it is being referenced by a FOREIGN KEY constraint.”

EXPLANATION:

If you try to delete the contents of a table referenced as a FOREIGN KEY in another table with the TRUNCATE TABLE command, you will receive this message.

SOLUTION:

If you want to delete the contents of a table that you reference as a FOREIGN KEY by another table then you can use the DELETE FROM command.

Alternatively, if you remove the FOREIGN KEY relationship then you can use the TRUNCATE TABLE command.

Msg 4712, Level 16, State 1, Line 1

Cannot truncate table ” because it is being referenced by a FOREIGN KEY constraint.

Exit mobile version