利用預存程序得到某一指定的表與其它的表之間的外鍵關係SQL Server2000

來源:互聯網
上載者:User
server|預存程序 --我參照的表名  我的果些欄位[5]要參照以下表[1]的某些欄位[3]的取值
declare  @id bigint
select  @id=id from sysobjects where name='d_病人資料庫'
select a. name N'被參照表名',b.rkey N'被參照列在被參照表中的位置',c.name N'被參照列名',b.fkey N'參照欄位在本表中的列位置' ,d.name  N'參照欄位名'
from sysforeignkeys b ,sysobjects a,syscolumns c ,(select name,colid from  syscolumns  where id=@ID ) d
where a.id=b.rkeyid and b.fkeyid=@ID  and c.id=a.id and c.colid=b.rkey and d.colid=b.fkey
---我被參的表名  以下的表[1]的某列[2]的取值要求參照我的哪些欄位[5]
select  a. name N'參照我的表名',c.name N'列名',b.fkey N'參照欄位位置' ,b.rkey N'我被參照欄位在表中的位置',d.name N'我被參照的欄位名'
 from sysforeignkeys b ,sysobjects a,syscolumns c ,(select name,colid from syscolumns where id=@ID) d
where a.id=b.fkeyid and b.rkeyid=@ID  and c.id=a.id and c.colid=b.fkey and d.colid=b.rkey


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.