sqlserver关联表
select object_name(ref.fkeyid) as foreigntable, col_name(ref.fkeyid, fk.fkey) as foreignkey,
object_name(ref.rkeyid) as primarytable, col_name(ref.rkeyid, fk.rkey) as primarykey
from sysreferences ref
join sysobjects obj on ref.constid=obj.id
join sysforeignkeys fk on obj.id=fk.constid
where object_name(ref.rkeyid)='主表' and col_name(ref.rkeyid, fk.rkey)='主键'

浙公网安备 33010602011771号