JK.Li 登录

Sql Server 得到表的外键名,对应的外键表名,对应的外键表里的字段,以及字段的描述

Posted by 2014/6/19 17:45:22  •  Author:JK.Li

select a.[name],rtableName,tname,a.[value],fcolid,fid,b.[value] from (select a.[name],rtableName,tname,[value],fcolid,fid from (select t1.name,t2.rtableName,t2.name  as tname,id,colid,fid,fcolid  from (select col.name, f.constid as temp,col.id,col.colid from syscolumns col,sysforeignkeys f  where f.fkeyid=col.id  and f.fkey=col.colid  and f.constid in  ( select distinct(id)     from sysobjects   where OBJECT_NAME(parent_obj)='{0}'    and xtype='F'   )  ) as t1 , (select OBJECT_NAME(f.rkeyid) as rtableName,col.name, f.constid as temp ,col.id as fid,col.colid as fcolid from syscolumns col,sysforeignkeys f  where f.rkeyid=col.id  and f.rkey=col.colid  and f.constid in  ( select distinct(id)    from sysobjects    where OBJECT_NAME(parent_obj)='{0}'    and xtype='F'  ) )  as t2 where t1.temp=t2.temp) as a left join sys.extended_properties as b on b.major_id = a.id and b.minor_id = a.colid) as a left join sys.extended_properties  as b on b.major_id = a.fid and b.minor_id = a.fcolid


Tagged: sql 外键信息  

Comments (0)  • 

0 评论列表

发表评论

京公网安备 11010702001442号