-- 从创建外键的表,获取外键名、字段,关联的主键表、主键名、字段(首字段)
SELECT fc.constrname fk_name,ft.tabname fk_tabname,fcol.colname fk_colname, pc.constrname pk_name, pt.tabname pt_tabname, pcol.colname
FROM sysreferences r, sysconstraints fc, sysconstraints pc, systables ft, systables pt, sysindexes fi, sysindexes pi, syscolumns fcol, syscolumns pcol
WHERE fc.constrtype = 'R'
AND fc.tabid = ft.tabid
AND fc.constrid = r.constrid
AND r.ptabid = pt.tabid
AND ft.tabid = fi.tabid
AND pt.tabid = pi.tabid
AND r.primary = pc.constrid
AND fc.idxname = fi.idxname
AND pc.idxname = pi.idxname
AND ft.tabid = fcol.tabid
AND pt.tabid = pcol.tabid
AND fi.part1 = fcol.colno
AND pi.part1 = pcol.colno
AND ft.tabname = 't12';
获取外键名、字段,关联的主键表、主键名、字段(首字段)
最新推荐文章于 2021-12-14 11:15:34 发布