Re: Finding a foreign key to any given table
Posted in 2004
On Tue, 12 Oct 2004 15:36:57 -0400, Mark J Fenbers wrote:
BTW, if all you want to know is what foreign key constraints depend on a
particular table you can use my dbschema replacement utility, myschema, with
the -F & -t options:
myschema -d mydatabase -t AAA -F
That will print the table or view's schema including any foreign keys that
reference the table and any views which reference the the table or view (or
which reference other views which do so).
Myschema is included in the package utils2_ak available for download from the
IIUG Software Repository.
Art S. Kagel
> Given a table existing in my database called "AAA", I can determine if a
> foreign key exists for "AAA" by looking up the "tabid" in the systables and
> finding any "R" constraints on the table by searching in sysconstraints for
> that tabid. Then, I can look up the constraint ID in the sysreferences
> table to find the ID of the table that is the "target" of the constraint
> (table "BBB").
>
> (I can even determine what column(s) in "AAA" are bound to a constraint by
> looking up the constraint ID in the sysindexes table.)
>
> But what I cannot seem to figure out is what column(s) in "BBB" are compared
> when Informix tests the constraint. Would this be the Primary Key for
> "BBB", or not necessarily so? If my software were to output a message upon
> encountering error -691, I would want to create a message that would be
> explicit about what table has to be updated and which columns in both "AAA"
> and "BBB" must match, so that the user knows how to eliminate this error...
>
> Any ideas?
>
> Mark