MySQL truncate含有外键约束的条目报错

2022-10-14,,,,

1.报错信息:

cannot truncate a table referenced in a foreign key constraint

2.出现错误操作:

truncate table a1;

为什么使用truncate?
使用truncate可以清空表数据,而且可以使自增列重置。

3.解决方法

mysql中取消外键约束set foreign_key_checks=0;

执行truncate table a1;

之后在设置外键约束:set foreign_key_checks=1;

《MySQL truncate含有外键约束的条目报错.doc》

下载本文的Word格式文档,以方便收藏与打印。