Incorrect value for UNIQUE_CONSTRAINT_NAME in REFERENTIAL_CONSTRAINTS

Posted by van on Stack Overflow See other posts from Stack Overflow or by van
Published on 2010-06-09T12:59:58Z Indexed on 2010/06/09 13:02 UTC
Read the original article Hit count: 184

I am listing all FK constraints for a given table using INFORMATION_SCHEMA set of views with the following query:

SELECT      X.UNIQUE_CONSTRAINT_NAME,
            "C".*, "X".*
FROM        "INFORMATION_SCHEMA"."KEY_COLUMN_USAGE" AS "C"
INNER JOIN  "INFORMATION_SCHEMA"."REFERENTIAL_CONSTRAINTS" AS "X"
        ON  "C"."CONSTRAINT_NAME" = "X"."CONSTRAINT_NAME" 
        AND "C"."TABLE_NAME" = 'MY_TABLE'
        AND "C"."TABLE_SCHEMA" = 'MY_SCHEMA'

Everything works perfectly well, but for one particular constraint the value of UNIQUE_CONSTRAINT_NAME column is wrong, and I need it in order to find additional information from the referenced Column. Basically, for most of the rows the UNIQUE_CONSTRAINT_NAME contains the name of the unique constraint (or PK) in the referenced table, but for one particular FK it is the name of some other unique constraint.

I dropped and re-created the FK - did not help.

My assumption is that the meta-data is somehow screwed. Is there a way to rebuild the meta data so that the INFORMATION_SCHEMA views would actually show the correct data?

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about sql-server-2008