检查参照完整性中断 [英] Check for referential integrity break

查看:85
本文介绍了检查参照完整性中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行过程中,我会执行以下操作:

In my process, I do something like:

SET FOREIGN_KEY_CHECKS = 0;
LOAD DATA INFILE '/path/to/mytable.txt' INTO TABLE mytable;
SET FOREIGN_KEY_CHECKS = 1;

现在,我需要检查此导入后的数据是否没有破坏参照完整性.我想做类似的事情

Now, I need to check that the data after this import is not breaking the referential integrity. I would like to do something like

check database all foreign_keys;

是否存在类似的命令?如果没有,该怎么做?

Is a similar command exists? If not, how to do this control?

环境:带有InnoDB的MySQL v5.1.xx

Environment: MySQL v5.1.xx with InnoDB

谢谢

推荐答案

答案

此处是满足您需要的一些代码.似乎没有这样的命令.

Answer

Here is some code which does what you need. It looks like there's no such command.

好的,我不是MySQL专家,但是除非您禁用它,否则引用完整性一直受到管理.除非先删除或禁用约束,否则您不能在违反约束的表中插入行.无需检查"它们.

OK, I'm not a MySQL expert but referential integrity is managed constantly unless you disable it. You cannot insert a row into a table which violates a constraint unless you've dropped or disabled the constraint first. There's no need to "check" them.

如果您确实禁用"了它们,则启用它们将强制执行检查.

这实际上是完全错误的,确实非常可怕. 至少在5.1中

This is in fact completely wrong and very scary indeed. at least in 5.1

我认为,如果他们具有该功能,那么当您重新启用约束时,他们只会调用它,所以我怀疑您会在服务器中找到它.

I think if they had that function, they would just call it when you re-enabled the constraints, so I doubt you'll find it in the server.

这篇关于检查参照完整性中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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