您想使用system
包含有关约束、视图等所有信息的表。http://msdn.microsoft.com/en-us/library/aa260604(v=sql.80).aspx
我会专门查看sysforeignkeys
等sysconstraints
并加入正确的 object_id,为此,您可以执行以下操作:
select t.name as TableWithForeignKey, fk.constraint_column_id as FK_PartNo , c.name as ForeignKeyColumn
from sys.foreign_key_columns as fk
inner join sys.tables as t on fk.parent_object_id = t.object_id
inner join sys.columns as c on fk.parent_object_id = c.object_id and fk.parent_column_id = c.column_id
where fk.referenced_object_id = (select object_id from sys.tables where name = 'TableOthersForeignKeyInto')
order by TableWithForeignKey, FK_PartNo
这将列出您表中的外键,您可以替换 WHERE name = 以使用 OBJECT_ID IN (.. all your object id's)
此脚本基于(如何列出引用 SQL Server 中给定表的所有外键?)的答案之一
编辑
从@Jacek 的评论中,您还可以使用stored procedure sp_depends
http://msdn.microsoft.com/en-us/library/ms189487.aspx