mysql - 在 MySQL 中,我可以将参照完整性检查推迟到提交之前吗

标签 mysql referential-integrity

this question ,我一直在阅读 PoEAA,想知道是否可以将参照完整性检查推迟到 MySQL 中提交。

我想在同一个提交中插入一堆产品和相关产品时遇到了这个问题。即使在事务中,当我尝试插入 related_products 连接表时也会遇到约束错误。

如果有帮助,我将使用 PHP PDO 进行数据库连接。

如果您能提供任何帮助,我将不胜感激。

最佳答案

看来我的答案是 here ...

Like MySQL in general, in an SQL statement that inserts, deletes, or updates many rows, InnoDB checks UNIQUE and FOREIGN KEY constraints row-by-row. When performing foreign key checks, InnoDB sets shared row-level locks on child or parent records it has to look at. InnoDB checks foreign key constraints immediately; the check is not deferred to transaction commit. According to the SQL standard, the default behavior should be deferred checking. That is, constraints are only checked after the entire SQL statement has been processed. Until InnoDB implements deferred constraint checking, some things will be impossible, such as deleting a record that refers to itself using a foreign key.

回到绘图板。

关于mysql - 在 MySQL 中,我可以将参照完整性检查推迟到提交之前吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5014700/

相关文章:

mysql - 在 MySQL 上迭代具有条件的行对

sql - 外键中的空值

mysql 一个表中的多个外键指向同一个主键

尝试在锁定的表上运行 sql 时 PHP 脚本挂起

mysql - 我是否应该合并两个具有相同列但每个表都与不同表有关系的表?

mysql - 将两个相似的查询组合在一起

database - 设置完整性约束会降低性能吗?

java - 使用 Liquibase 删除 MySQL 表

mysql - SQL 递归引用完整性

sql-server - 如何在检查约束中引用其他表?