2012-07-30 47 views
3

我希望能够在列中搜索Informix数据库。在主表中有一个cust_nbr列,然后在未知数量的表中引用。如何在列中搜索informix数据库

在Informix中,有没有办法查询数据库并获取所有使用cust_nbr的表?

回答

4
SELECT tabname, colno, colname 
FROM systables a, syscolumns b 
WHERE a.tabid = b.tabid 
and colname = "cust_nbr" 
ORDER BY colno; 

我发现在同一个地方的代码,并与colname的= cust_nbr添加的额外restriant。

这似乎对我有用。我会验证它,但所有迹象看起来像它的工作。

我发现,在其他文章中提到的Using the Informix Catalogs

0

您应该能够从system catalog tables,sysreferences中获得这种类型的东西。从Using the Informix System Catalog采取:

SELECT a.tabname, constrname, d.tabname 
    FROM systables a, sysconstraints b, sysreferences c, 
     systables d 
WHERE b.constrtype = 'R' 
    AND a.tabid = b.tabid 
    AND b.constrid = c.constrid 
    AND c.ptabid = d.tabid 
    AND a.tabname = ?; 
+0

所以我一直在寻找的文件,当你张贴了这个。我在哪里把栏“cust_nbr”? – zach 2012-07-30 13:50:48

+0

通过一些艰苦的工作,可以识别包含给定列名的外键(这可能是两个表上两个16部分索引中的每一个的第16列;这是艰巨的工作!),但它是间接的,并不是列名的所有用途都需要处于这样的限制。 SysTables和SysColumns的直接选择要简单得多。 – 2012-07-31 17:17:23