SELECT ccu.TABLE_SCHEMA + '.' + ccu.TABLE_NAME + '.' + c...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

SELECT  ccu.TABLE_SCHEMA + '.' + ccu.TABLE_NAME + '.' + 
    ccu.COLUMN_NAME AS ForeignKeyColumn,
        ccu2.TABLE_SCHEMA + '.' + ccu2.TABLE_NAME + '.' + 
    ccu2.COLUMN_NAME AS PrimaryKeyColumn
FROM    INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS rc
JOIN    INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu
        ON rc.CONSTRAINT_CATALOG = ccu.CONSTRAINT_CATALOG
        AND rc.CONSTRAINT_SCHEMA = ccu.CONSTRAINT_SCHEMA
        AND rc.CONSTRAINT_NAME = ccu.CONSTRAINT_NAME
JOIN    INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu2
        ON rc.UNIQUE_CONSTRAINT_CATALOG = ccu2.CONSTRAINT_CATALOG
        AND rc.UNIQUE_CONSTRAINT_SCHEMA = ccu2.CONSTRAINT_SCHEMA
        AND rc.UNIQUE_CONSTRAINT_NAME = ccu2.CONSTRAINT_NAME

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results