Stupidly, I truncated my posts table with out thinking about the term relationships. Now I have a bunch of 404s because there are broken term relationships. Is is possible to rebuild the table with the correct pairings?

2 Answers
If your AUTO_INCREMENT
value wasn’t reset and your new posts will still have unique ID
s and you can do:
SELECT tr.*, p.ID
FROM wp_term_relationships AS tr
LEFT JOIN wp_posts AS p ON tr.object_id = p.ID
WHERE p.ID is NULL;
to see which term relationships are orphans and use a DELETE FROM
to fix it.