如 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/