截断所有表(其中大多数都有约束).如何暂时放下它们 [英] Truncate all tables (most of which have constraints). How to temporarily drop them

查看:71
本文介绍了截断所有表(其中大多数都有约束).如何暂时放下它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个开发数据库(MYSQL),我想在某个时候加载新数据.我想删除所有表的内容. 最好的自动删除所有表(包括具有外键约束的表)内容的最佳方法是什么.是否有一个全部截断/删除所有等效约束的子句?

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 automated as possible, to delete the content of all tables (including those that have foreign key constraints). Is there a truncate all/ drop all equivalent constraints?

谢谢

推荐答案

我认为您可以执行以下操作:

I think you can do the following:

  1. 禁用外键约束检查

  1. Disable the foreign key constraint check

mysql> SET FOREIGN_KEY_CHECKS = 0;

  • 截断表格

  • Truncate your tables

    mysql> TRUNCATE MY_TABLE;
    

  • 启用外键约束检查

  • Enable the foreign key constraint check

    mysql> SET FOREIGN_KEY_CHECKS = 1;
    

  • 与删除/重新创建外键相比,我更喜欢暂时禁用外键约束.

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

    这篇关于截断所有表(其中大多数都有约束).如何暂时放下它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆