Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > IBM DB2 > Re: Question on...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 6 Topic 9029 of 9520
Post > Topic >>

Re: Question on syscat.keycoluse.colseq

by "Dave Hughes" <dave@[EMAIL PROTECTED] > Jun 27, 2008 at 08:26 AM

Lennart wrote:

> On Jun 27, 10:31 am, Lennart <Erik.Lennart.Jons...@[EMAIL PROTECTED]
> wrote:
> [...]
> > The other day I stumbled upon an error. The foreign keys
> > are working as expected, but syscat.keycoluse.colseq indicates
> > otherwise(I'm aware that syscat.references can be used instead, this
> > is more of a nice to know thing)
> 
> Hmm, on second thought. Looking in:
> 
> SQL Reference Volume 1, Version 8. (havent checked 9.5 yet) in the
> comment on syscat.references it says:
> 
> FK_COLNAMES:"List of foreign key column names. Warning: This column
> will be removed in the future.Use SYSCAT.KEYCOLUSE for this
> information."
> 
> PK_COLNAMES: "List of parent key column names. Warning: This column
> will be removed in the future. Use SYSCAT.KEYCOLUSE for this
> information."
> 
> But as shown in my earlier post, KEYCOLUSE.COLSEQ does not necessarily
> reflect the colorder in the key. Reflections anyone?

Indeed, FK_COLNAMES and PK_COLNAMES are still there in 9.5, but they've
been deprecated for a while now. I tested out the DDL you posted on our
9.5 FP1 box and came up with the exact same results (incorrect ordering
in KEYCOLUSE).

Insertions and deletions to both tables worked fine, so the keys are
defined properly - it's just that SYSCAT.KEYCOLUSE isn't re****ting them
correctly. The deprecated FK_COLNAMES and PK_COLNAMES columns are
re****ting them in the correct order.

I also tested the following query, which is a tweaked version of a
query I use in my do***entation system for obtaining the mapping of
foreign key columns to primary key columns:

SELECT
    SUBSTR(R.CONSTNAME, 1, 18) AS KEYNAME,
    SUBSTR(KF.COLNAME, 1, 18)  AS COLNAME,
    SUBSTR(KP.COLNAME, 1, 18)  AS REFCOLNAME
FROM
    SYSCAT.REFERENCES R
    INNER JOIN SYSCAT.KEYCOLUSE KF
        ON R.TABSCHEMA = KF.TABSCHEMA
        AND R.TABNAME = KF.TABNAME
        AND R.CONSTNAME = KF.CONSTNAME
    INNER JOIN SYSCAT.KEYCOLUSE KP
        ON R.REFTABSCHEMA = KP.TABSCHEMA
        AND R.REFTABNAME = KP.TABNAME
        AND R.REFKEYNAME = KP.CONSTNAME
WHERE
    R.TABNAME = 'COURSE_OFFERING_ADV_PRG_ELIG'
    AND KF.COLSEQ = KP.COLSEQ
ORDER BY
    R.TABSCHEMA,
    R.TABNAME,
    R.CONSTNAME,
    KF.COLSEQ
WITH UR;

Naturally, the results were:

KEYNAME            COLNAME            REFCOLNAME
------------------ ------------------ ------------------
XFK1CO_ADV_PRG_ELG COURSEOFFERING_ID  ADMISSIONROUND_ID
XFK1CO_ADV_PRG_ELG EDUCATIONORG_ID    EDUCATIONORG_ID
XFK1CO_ADV_PRG_ELG ADMISSIONROUND_ID  COURSEOFFERING_ID

Oh dear. I'd suggest opening a PMR for this - looks like a bug to me.


Cheers,

Dave.
 




 6 Posts in Topic:
Question on syscat.keycoluse.colseq
Lennart <Erik.Lennart.  2008-06-27 01:31:57 
Re: Question on syscat.keycoluse.colseq
Lennart <Erik.Lennart.  2008-06-27 02:10:02 
Re: Question on syscat.keycoluse.colseq
"Dave Hughes" &  2008-06-27 08:26:26 
Re: Question on syscat.keycoluse.colseq
Lennart <Erik.Lennart.  2008-06-27 07:18:09 
Re: Question on syscat.keycoluse.colseq
Arun Srinivasan <arunr  2008-06-30 08:05:03 
Re: Question on syscat.keycoluse.colseq
Lennart <Erik.Lennart.  2008-07-17 05:24:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 21:10:00 CST 2008.