如何在Informix中查找父记录的引用记录

4

我想在我的数据库中删除一个人:

delete from person where id in (14)

但我遇到了以下异常:

Key value for constraint (pk_person_id) is still being referenced.

我不知道这个人还有哪些记录,因为我大约有100个引用表。在Informix中有没有找到这些记录的方法?

PS:我无法删除约束。

1个回答

10

你可以尝试这个,它会找到所有其他表格,在这些表格中外键与Person表的主键匹配,并且在Person表中该列存在值的情况下。

select e.tabname,g1.colname
from systables a,
sysconstraints b,
sysreferences c,
sysconstraints d,
systables e,
sysindexes f,
syscolumns g1
where a.tabname='person' and
a.tabid=b.tabid and b.constrtype='P' and
b.constrid=c.primary and
b.tabid=c.ptabid and
c.constrid=d.constrid and
d.tabid=e.tabid and
e.tabid=f.tabid and
f.idxname=d.idxname and
f.tabid=g1.tabid and abs(f.part1)=g1.colno
;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接