Thanks, Andreas; that is certainly a starting point. You state:
sysreferences is your friend, its primary column pointing to the (PK or Unique) constraint on the referenced table
OK, here are the columns of both catalogs:
sysconstraints: |
|
sysreferences: |
Column name Type |
|
Column name Type |
|
|
|
constrid serial |
|
constrid integer |
constrname varchar(128,0) |
|
primary integer |
owner char(32) |
|
ptabid integer |
tabid integer |
|
updrule char(1) |
constrtype char(1) |
|
delrule char(1) |
idxname varchar(128,0) |
|
matchtype char(1) |
collation char(36) |
|
pendant char(1) |
Thus, making a few guesses, I can up with this query, that seems to correctly match up master and detail tables:
select tp.tabname pk_tabname, tr.tabname fk_tabname, c.idxname,
c.constrname, c.constrtype,
c.constrid, c.tabid detail_tabid, r.ptabid master_tabid,
r.primary
from sysconstraints c, systables tr, systables tp, sysreferences r
where tr.tabid = c.tabid
and tp.tabid = r.ptabid
--and r.primary = c.constrid
and r.constrid = c.constrid
and c.constrtype = "R"
order by 1, 2
Notice: The one line mentioning column primary in the WHERE clause is commented out. If I include it I get no rows found. What column it sysreferences.primary supposed to correlate with, if not the constrid of the PK table?
Now, as I said in opening, this is a start. I see that Art K piped in while I was composing this response. From his solution I can gain an understanding of primary. I think.. And he has the column names accounted for! But it requires study, which I will give it.
Thank you much, gentlemen!
------------------------------
+-----------------------------------------------------------+
| I am pleased to report that I had no problems today. |
| I had only issues, opportunities, challenges and valuable |
| learning experiences. |
+------------------------------------------ Jacob S --------+
------------------------------
Original Message:
Sent: Wed December 17, 2025 04:26 PM
From: Andreas Legner
Subject: How can I reconstruct foreign key constraints from system catalogs?
sysreferences is your friend, its primary column pointing to the (PK or Unique) constraint on the referenced table.
------------------------------
Andreas Legner
Informix Dev
HCL Software
Original Message:
Sent: Wed December 17, 2025 03:57 PM
From: Jacob Salomon
Subject: How can I reconstruct foreign key constraints from system catalogs?
Hi again, Family.
At least 10 years ago I posted a question about retrieving information of foreign key constraints. Of course, we have a method to get this in dbaccess:
dbaccess <database>
-> Query-language
-> Info
-> (Select table)
-> cOnstraints (Press letter O)
-> Reference
-> referenceD (Press D)
This gives me a nice list of all foreign key constraints on other tables that reference the selected table.
Minor annoyance: A long constraint name will get truncated.
What system catalogs control these constraints? I know sysconstraints is involved because I was able to select from sysconstraints where constrname = "<first column in the above list>". And I see that the constrtype == R. But where do I find on the table being referenced?
When I asked this over 10 years ago, someone responded that I would need to join with information in some undocumented system catalog and told me which ones. To my shock, I see that I have not saved the SQL. Perhaps I posted it in IIUG Software Repository but after 10+ years, where is that?
HMMM... If I could search this forum for my old postings it would also be helpful.
Ideas, anyone, please?
Thanks for advice here.
------------------------------
+-----------------------------------------------------------+
| I am pleased to report that I had no problems today. |
| I had only issues, opportunities, challenges and valuable |
| learning experiences. |
+------------------------------------------ Jacob S --------+
------------------------------