简体   繁体   English

从MySql数据库中截断或删除表

[英]Truncate or Delete tables from the MySql database

I have a databse called store having 100 tables having too much foreign key references with tables, having thousands of records. 我有一个名为store的数据库,其中有100个表,其中表的foreign key references过多,具有数千条记录。

Problem : Is it possible something like truncate to delete all the rows of all the tables in a single query. 问题 :是否有可能像truncate这样在单个查询中删除所有表的所有行。

I tried but I am not able to find the exact way to achieve this when I try to TRUNCATE TABLE it gives me error: Cannot delete or update a parent row: a foreign key constraint fails which is expected too. 我尝试过,但是当我尝试使用TRUNCATE TABLE时我无法找到实现此目标的确切方法,它给了我错误: Cannot delete or update a parent row: a foreign key constraint fails也将Cannot delete or update a parent row: a foreign key constraint fails

Can anyone please help me to achieve this, or suggest me the better way to do this. 任何人都可以请帮助我实现这一目标,或者向我提出实现此目标的更好方法。

Do this before deleting: 在删除之前执行此操作:

SET FOREIGN_KEY_CHECKS=0;

When finished, reset it to 1: 完成后,将其重置为1:

SET FOREIGN_KEY_CHECKS=1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM