Why should an importer check foreign-key enforcement on its connection?

Foreign-key enforcement is connection-specific. Configure and inspect it before opening the transaction that imports related records.

SQLite example and interpretation

Enabling checks on an application connection does not establish the state of a new importer connection. A returned one confirms enforcement here.

PRAGMA foreign_keys=ON;
PRAGMA foreign_keys;

Result [[1]]

中文

为什么导入程序需要检查当前连接的外键设置?

SQLite 的外键执行状态按连接设置,应在事务开始前配置并通过 PRAGMA 读取确认。

SQLite 示例与适用条件

一个连接启用约束,不代表新建的导入连接也会检查孤儿记录。读取结果 1 表示此连接已开启。

PRAGMA foreign_keys=ON;
PRAGMA foreign_keys;

结果 [[1]]

References / 参考来源

Keep reading / 继续阅读