--找主外键关系的查询函数(1):
select fk.*
,obj.name --外键名
,obj2.name --外键表
,obj3.name --主键表
from sysforeignkeys fk inner join sysobjects obj on fk.constid=obj.id
inner join sysobjects obj2 on fk.fkeyid = obj2.id
inner join sysobjects obj3 on fk.rkeyid = obj3.id
order by obj2.name
select fk.*
,obj.name --外键名
,obj2.name --外键表
,obj3.name --主键表
from sysforeignkeys fk inner join sysobjects obj on fk.constid=obj.id
inner join sysobjects obj2 on fk.fkeyid = obj2.id
inner join sysobjects obj3 on fk.rkeyid = obj3.id
order by obj2.name