1. 程式人生 > >查詢sql server2005中所有的外來鍵資訊

查詢sql server2005中所有的外來鍵資訊

鍵名    從表    外來鍵列   主表

 

select fk.name fkname , ftable.name ftablename, cn.name fkcol, rtable.name ftablename from sysforeignkeys
  join sysobjects fk
    on sysforeignkeys.constid = fk.id
  join sysobjects ftable
    on sysforeignkeys.fkeyid = ftable.id
  join sysobjects rtable
    on sysforeignkeys.rkeyid = rtable.id
  join syscolumns cn
    on sysforeignkeys.fkeyid = cn.id and sysforeignkeys.fkey = cn.colid
where