Wishlist 0 ¥0.00

mysql设置外键约束开启-关闭

在MySQL中删除一张表或一条数据的时候,出现

[Err] 1451 -Cannot delete or update a parent row: a foreign key constraint fails (...)
这是因为MySQL中设置了foreign key关联,造成无法更新或删除数据。可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况。

 

我们可以使用

    SET FOREIGN_KEY_CHECKS=0;
来禁用外键约束.
 
之后再用
    SET FOREIGN_KEY_CHECKS=1;
来启动外键约束.
 
查看当前FOREIGN_KEY_CHECKS的值可用如下命令

    SELECT  @@FOREIGN_KEY_CHECKS;

About Us

Since 1996, our company has been focusing on domain name registration, web hosting, server hosting, website construction, e-commerce and other Internet services, and constantly practicing the concept of "providing enterprise-level solutions and providing personalized service support". As a Dell Authorized Solution Provider, we also provide hardware product solutions associated with the company's services.
 

Contact Us

Address: No. 2, Jingwu Road, Zhengzhou City, Henan Province

Phone: 0086-371-63520088 

QQ:76257322

Website: 800188.com

E-mail: This email address is being protected from spambots. You need JavaScript enabled to view it.