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

后端 未结 4 1480
清酒与你
清酒与你 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条回答
  •  猫巷女王i
    2021-02-02 18:20

    TRUNCATE (TABLE) tbl_name will truncate a single table. You can stick that in a script and loop through it with all of your table names.

    http://dev.mysql.com/doc/refman/5.0/en/truncate.html

    You may want to look into migrations, too, but I think Alexey has the right approach there. It's very similar to how RoR handles rebuilding the test database on each run.

提交回复
热议问题