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

xiaoxiao2021-03-06  94

- I'm using the name of my specification [5] to refer to the value of some fields [1] [3]

Declare @ID bigint

SELECT @ id = id from sysobjects where name = 'd_ patient database'

Select a. name n 'is referred to the table name', B.RKey N 'is referred to in the reference list in the reference table', the c.Name N 'is referred to the list', the B.fkey n 'referred to the reference field in this table Column location ', 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 have the table name below [1] of the table [1] to take the value of the value of the value of me [5]

Select a. name n 'Refer to my table name', c.name n 'column name', B.FKEY N 'Reference Field Location', B.RKey N 'I was referred to in the field', D. Name n 'I was named by the 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

转载请注明原文地址:https://www.9cbs.com/read-95719.html

New Post(0)