0

I'm using LOAD DATA to batch csv content into a TEMPORARY table, with deactivated auto-commit. Within the same transaction, I then INSERT... ON DUPLICATE KEY UPDATE the content from temp table into the production table. After that, I COMMIT the transaction.

I have several files, and each of them runs the transaction described above.

Question: should I DROP and recreate the temporary table before each commit? Because I don't need the data in the temporary table anymore, plus I need a fresh temporary table for each file import. Or should I better simply TRUNCATE the temporary table?

2
  • 2
    Both are same only either or DROP & recreate, Truncate will internal do same DROP & recreate. But still if no other concern go with TRUNCATE because everything will be managed itself. Commented Apr 28, 2020 at 11:04
  • 1
    should I DROP and recreate the temporary table before each commit? If the structures of previous and next temptables are the same then TRUNCATE is enough. Else - DROP is more safe then TRUNCATE + ALTER TABLE.
    – Akina
    Commented Apr 28, 2020 at 13:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.