I have SQL that contains some details about a table.
SELECT Column_Name, Is_Nullable, Data_Type, Character_Maximum_Length
FROM Information_Schema.Columns
WHERE Table_Name='GenSchool'
This has been working fine so far and returns row by column in the table. However, I want it to also return some foreign key details. For example, it GenSchoolhas a column SchoolTypethat has FK up GenSchoolType.Code.
Like the columns selected above, I need a query to return the table name FK and the column name of the linked table or NULL where the column does not have FK.
This is returned from the request above.
Code NO nvarchar 10
CodeDescription YES nvarchar 80
Deleted NO bit NULL
Type NO nvarchar 20
And I would like for him to return something like
Code NO nvarchar 10 NULL NULL
CodeDescription YES nvarchar 80 NULL NULL
Deleted NO bit NULL NULL NULL
Type NO nvarchar 20 GenSchoolType Code
I’ve been trying for centuries to use internal joins in tables sys, but I’m not going anywhere. If you need me to show what I tried, I can.
Thanks in advance.
source
share