SQL SERVER查询关联某表字段的信息

1.查询关联某表字段的所有表
SELECT OBJECT_NAME (f.object_id) FK_name
	 , OBJECT_NAME (f.parent_object_id) tab_name
	 , fc.parent_column_id
	 , OBJECT_NAME (fc.referenced_object_id) Refer_TabName
	 , c.name Refer_ColName
FROM sys.foreign_keys f, sys.foreign_key_columns fc, sys.columns c
WHERE fc.constraint_object_id = f.object_id
	AND (c.column_id = fc.referenced_column_id and c.object_id = fc.parent_object_id)
	AND OBJECT_NAME (fc.referenced_object_id) = 'tabName'


2.查询关联某表字段的所有视图
SELECT * FROM INFORMATION_SCHEMA.VIEW_COLUMN_USAGE WHERE TABLE_SCHEMA = 'xxx' AND TABLE_NAME = 'tabName' AND COLUMN_NAME = 'FundID'

你可能感兴趣的:(SQL Server)