建立外键约束时报错。
ORA-02298错误:在父表里找不到子表里存在的数据。引用的数据不存在。
定位问题数据的SQL语句如下:
SELECT A.*
FROM CHILD_TABLE_NAME A
WHERE NOT EXISTS (SELECT 1
FROM PARENT_TABLE_NAME B
WHERE A.FOREIGN_KEY = B.PRIMARY_KEY);
A为数量多的表,B为被引用的表,被引用的是B的主键,通常关联B的Id