Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-14
5
Medium Priority
?
558 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 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 600 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 1400 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 60

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

971 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