Get relationship between tables using foreign key relationships!
SELECT Referencing_Object_name, Referencing_Column_Name, Referenced_Object_Name, Referenced_Column_Name FROM
(SELECT Referenced_Column_Name = c.name, Referenced_Object_name = o.name, f.constid FROM sysforeignkeys f, sysobjects o, syscolumns c WHERE (f.rkeyid = o.id) AND c.id = o.id AND c.colid = f.rkey) r,
(SELECT referencing_column_Name = c.name, Referencing_Object_name = o.name, f.constid FROM sysforeignkeys f, sysobjects o, syscolumns c WHERE (f.fkeyid = o.id) AND c.id = o.id AND c.colid = f.fkey) f
WHERE r.Referenced_Column_Name = f.referencing_column_Name AND r.constid = f.constid
ORDER BY f.Referencing_Object_name
SQL Server 2008 (Formerly code name Katmai) June CTP available now
The most awaited CTP of SQL Server 2008 (Formerly code name Katmai) has been released on June04, 2007.
You can download it from http://connect.microsoft.com/sqlserver. You can also watch Ted Kummert talking about SQL Server 2008 here
Some of the key improvements in this CTP are: Read the rest of this entry »