日期:2014-05-17 浏览次数:20458 次
--查询外键
select b.name FK_Name,c.name ForeignTable,d.name ForeignCol,e.name refTable,f.name refCol
from sysforeignkeys a
inner join sysobjects b on a.constid=b.id
inner join sysobjects c on a.fkeyid=c.id
inner join syscolumns d on a.fkeyid=d.id and a.fkey=d.colid
inner join sysobjects e on a.rkeyid=e.id
inner join syscolumns f on a.rkeyid=f.id and a.rkey=f.colid
--查询表名与字段名
select a.name as 表名,b.name as 字段名
from sysobjects a
left join syscolumns b on a.id=b.id
where a.xtype='U'
order by a.name,b.name