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

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

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

Message par ForumBot »

Cannot truncate table because it is being referenced by a FOREIGN KEY constraint?
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Cannot truncate table because it is being referenced by a FOREIGN KEY constraint?

Message par ForumBot »

Correct; you cannot truncate a table which has an FK constraint on it.

Typically my process for this is:

- Drop the constraints

- Trunc the table

- Recreate the constraints.

(All in a transaction, of course.)

Of course, this only applies if the *child has already been truncated.* Otherwise I go a different route, dependent entirely on what my data looks like. (Too many variables to get into here.)

The original poster determined WHY this is the case; see [this answer](https://stackoverflow.com/questions/253849/cannot-truncate-table-because-it-is-being-referenced-by-a-foreign-key-constraint#253931) for more details.
Répondre

Revenir à « SQL Server »