Solved

How to find out Primary Key information in the system tables?

Posted on 2011-09-14
5
546 Views
Last Modified: 2013-12-24
In Informix, is there a way to find out the Primary Key information in the system tables?  Thanks.
0
Comment
Question by:thomaszhwang
  • 2
  • 2
5 Comments
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 150 total points
ID: 36540607
Hi. You want to check the SYSCONSTRAINTS. You specifically want to look for constrtype = 'P' for Primary key.

Hope that helps!

Kevin
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 36540622
- to add further, you can use the following query, it will return the tablename for that Primarykey as the SYSCONSTRAINTS only contain the tableid :

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

http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqlr.doc/sqlrmst47.htm
0
 
LVL 23

Accepted Solution

by:
OP_Zaharin earned 350 total points
ID: 36540625
- correction change R code to P for primary key:

SELECT a.tabname, constrname, d.tabname
  FROM systables a, sysconstraints b, sysreferences c,
       systables d
 WHERE b.constrtype = 'P'
   AND a.tabid = b.tabid
   AND b.constrid = c.constrid
   AND c.ptabid = d.tabid
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 36540779
OP_Zaharin: thanks! It appears that because of the frames on IBM's site, my version of the link went to SYSCOLUMNS and not SYSCONSTRAINTS, so you provide both a wonderful code sample and the correct link. :)
0
 

Author Closing Comment

by:thomaszhwang
ID: 36543616
Thank you guys.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now