Diagnosing referential integrity using TSQL

Quite often you work on databases that you didn't write. Getting up to speed on the structure of the tables and the relationships between them is not something you relish. The GUIs provided by SQL Server 2000 or 2005 don't always provide the best way, particularly with regard to complex referential integrity.

I've always used a few TSQL procedures to accelerate the process, and hopefully reduce the pain...

sp_help, returns information about a database object (any object listed in the sysobjects table), a user-defined data type, or a data type supplied by Microsoft SQL Server. There are quite a few "sp_helps", they are worth checking.

sp_fkeys, returns all tables that include a foreign key to the given table

sp_pkeys, returns primary key information for a single table.