Cannot truncate table because it is being referenced by a FOREIGN KEY constraint?
Cannot truncate table because it is being referenced by a FOREIGN KEY constraint?
Cannot truncate table because it is being referenced by a FOREIGN KEY constraint?
Re: Cannot truncate table because it is being referenced by a FOREIGN KEY constraint?
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.
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.