select 外键表=object_name(b.fkeyid),
外键表列=(select name from syscolumns where colid=b.fkey and id=b.fkeyid),
外键名=a.name,
主键表=object_name(b.rkeyid),
主键表列=(select name from syscolumns where colid=b.rkey and id=b.rkeyid),
主键名=(select name from sysobjects where xtype='PK' and parent_obj=c.id)
from sysobjects a
join sysforeignkeys b on a.id=b.constid
join sysobjects c on a.parent_obj=c.id
where a.xtype='F' and c.xtype='U'
外键表列=(select name from syscolumns where colid=b.fkey and id=b.fkeyid),
外键名=a.name,
主键表=object_name(b.rkeyid),
主键表列=(select name from syscolumns where colid=b.rkey and id=b.rkeyid),
主键名=(select name from sysobjects where xtype='PK' and parent_obj=c.id)
from sysobjects a
join sysforeignkeys b on a.id=b.constid
join sysobjects c on a.parent_obj=c.id
where a.xtype='F' and c.xtype='U'
exec sp_helpconstraint 'table_name'