Forums - C# Corner

Forum guidelines
Ramon Quintana

Ramon Quintana

  • 1.7k
  • 110
  • 2.2k

Hi, i need to know the FK from one table

Nov 8 2018 1:37 PM
I wrote this code trying to know the relations amongs other tables from my BD but it didn´t bring nothing.
USE tuBaseDeDatos; 
GO  DECLARE @tabName AS Varchar(50) 
SET @tabName = 'dbo.TU_TABLA'--table´s name from fk´s are goint to get 
 SELECT OBJECT_NAME(f.constid) AS 'FKName', AS 'ColName'
 FROM sysforeignkeys f INNER JOIN syscolumns c 
ON f.fkeyid = AND f.fkey = c.colid
 WHERE fkeyid = OBJECT_ID(@tabName)

Answers (8)