我會在SQLServerManagementStudio中使用數據庫圖表功能,但由于您排除了這種情況-這在SQLServer 2008中是有效的(請不要使用2005年)。
要獲得引用表和列名的列表.。
select
t.name as TableWithForeignKey,
fk.constraint_column_id as FK_PartNo, c.
name as ForeignKeyColumn
from
sys.foreign_key_columns as fkinner join
sys.tables as t on fk.parent_object_id = t.object_idinner join
sys.columns as c on fk.parent_object_id = c.object_id and fk.parent_column_id = c.column_idwhere
fk.referenced_object_id = (select object_id
from sys.tables
where name = 'TableOthersForeignKeyInto')order by
TableWithForeignKey, FK_PartNo
獲取外鍵約束的名稱
select distinct name from sys.objects where object_id in ( select fk.constraint_object_id from sys.foreign_key_columns as fk
where fk.referenced_object_id =
(select object_id from sys.tables where name = 'TableOthersForeignKeyInto'))