sql server 2008 如何快速查看一个数据库中所有表的关联关
要修改一个项目、看他的数据库里的表关系看得很烦、用的是sqlserver2008; 我想问下:sqlserver数据库里有没有快速可以查看出数据库里表的关系啊?请指教!!!
------解决方案----------------------sql 语句查找外键 以及对应的外键表名、列名和引用的主表名、列名
;WITH CTE
AS (
SELECT OBJECT_NAME(constraint_object_id) Constraint_Name , OBJECT_NAME(parent_object_id) Table_Name , C.name Column_Name
FROM sys.foreign_key_columns FK
INNER JOIN sys.columns C
ON FK.parent_object_id = C.object_id
AND FK.parent_column_id = C.column_id
)
SELECT C.Constraint_Name , C.Table_Name , C.Column_Name , OBJECT_NAME(FK.referenced_object_id) Referenced_Table_Name , SC.name Referenced_Column_Name
FROM CTE C
INNER JOIN sys.foreign_key_columns FK
ON C.Constraint_Name = OBJECT_NAME(FK.constraint_object_id)
INNER JOIN sys.columns SC
ON FK.referenced_object_id = SC.object_id
AND FK.referenced_column_id = SC.column_id