Use a stored procedure to get a foreign key relationship between a specified table and other tables SQL Server2000

Source: Internet
Author: User
Server| stored Procedure--I refer to the table name my fruit some fields [5] to refer to some of the fields [3] in the following table [1]
DECLARE @id bigint
Select @id =id from sysobjects where name= ' d_ patient database '
Select a. Name n ' referenced table name ', B.rkey N ' is referred to as the position in the referenced table ', c.name n ' referenced column name ', B.fkey N ' Reference field in this table column position ', d.name n ' Reference field name '
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
---I'm being called. The value of a column [2] of the table [1] below is called to refer to my fields [5]
Select a. Name n ' reference my table name ', c.name N ' column name ', B.fkey n ' Reference field position ', B.rkey n ' I am referenced field in table ', D.name n ' I referenced field name '
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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.