I'm using the INFORMATION_SCHEMA views in Sql Server 2005 & 2008 to obtain metadata for a database:
SELECT
PK.TABLE_NAME as 'PK_TABLE_NAME',
FK.TABLE_NAME as 'FK_TABLE_NAME',
C.CONSTRAINT_NAME as 'CONSTRAINT_NAME'
FROM
INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C
JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME
JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME
WHERE
FK.TABLE_NAME = 'Table_Name'
However, if I have a nullable foreign key on the table it is not included in my results because there is no matching entry for the "UNIQUE_CONSTRAINT_NAME" column.
I'm struggling to work out how to obtain information about nullable foreign keys (specifically, the name of the referenced table and column) using views in the INFORMATION_SCHEMA schema. Apparently indexes aren't part of the standard, and hence aren't included in the views.
Does anyone know how I might alter my query to obtain information about nullable foreign keys?
Edit
As an aside, it would appear that SQL Server Compact Edition has an INFORMATION_SCHEMA.INDEXES view - why does CE get this useful information?!