SELECT  C.TABLE_CATALOG  
,       C.TABLE_SCHEMA  
,       C.TABLE_NAME  
,       C.COLUMN_NAME  
,       C.DATA_TYPE  
,       C.CHARACTER_MAXIMUM_LENGTH    AS CHAR  
,       C.CHARACTER_OCTET_LENGTH      AS BYTE  
,       C.NUMERIC_PRECISION  
,       C.NUMERIC_SCALE  
,       CASE    C.IS_NULLABLE
                WHEN 'YES'  THEN 'NULL'
                WHEN 'NO'   THEN 'NOT NULL'
        END AS NULLABLE  
,       C.COLUMN_DEFAULT  
,       C.ORDINAL_POSITION  
,       K.PK  
,       K.FK  
FROM INFORMATION_SCHEMA.COLUMNS C  
LEFT OUTER JOIN (SELECT TABLE_CATALOG
                ,       TABLE_SCHEMA
                ,       TABLE_NAME
                ,       COLUMN_NAME
                ,       MAX(PK) AS PK
                ,       MAX(FK) AS FK
                FROM    (SELECT P.TABLE_CATALOG
                        ,       P.TABLE_SCHEMA
                        ,       P.TABLE_NAME
                        ,       P.COLUMN_NAME
                        ,       CASE    WHEN F.CONSTRAINT_NAME IS NULL
                                        THEN P.CONSTRAINT_NAME
                                        ELSE NULL
                                END AS PK
                        ,       F.CONSTRAINT_NAME AS FK
                        FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE P
                        LEFT OUTER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS F    ON  F.CONSTRAINT_CATALOG    = P.CONSTRAINT_CATALOG
                                                                                        AND F.CONSTRAINT_SCHEMA     = P.CONSTRAINT_SCHEMA
                                                                                        AND F.CONSTRAINT_NAME       = P.CONSTRAINT_NAME) K
                GROUP BY    TABLE_CATALOG
                ,           TABLE_SCHEMA
                ,           TABLE_NAME
                ,           COLUMN_NAME) K  ON  K.TABLE_CATALOG = C.TABLE_CATALOG
                                            AND K.TABLE_SCHEMA  = C.TABLE_SCHEMA
                                            AND K.TABLE_NAME    = C.TABLE_NAME
                                            AND K.COLUMN_NAME   = C.COLUMN_NAME
ORDER BY    C.TABLE_NAME ASC  
,           C.ORDINAL_POSITION ASC;