Truncate all tables (most of which have constraints). How to temporarily drop them

后端 未结 4 1470
清酒与你
清酒与你 2021-02-02 17:59

I have a development database (MYSQL) which I would like to load with fresh data at some point. I would like to delete the content of all tables. What is the best way, as autom

4条回答
  •  一向
    一向 (楼主)
    2021-02-02 18:26

    I think you can do the following:

    1. Disable the foreign key constraint check

      mysql> SET FOREIGN_KEY_CHECKS = 0;
      
    2. Truncate your tables

      mysql> TRUNCATE MY_TABLE;
      
    3. Enable the foreign key constraint check

      mysql> SET FOREIGN_KEY_CHECKS = 1;
      

    I prefer disabling the foreign key constraints temporarily to dropping/recreating them.

提交回复
热议问题