In another solution I asked to find all occurances of a particular field name in the DB. I have some missing foreign keys and I want to find all instances of a column named "order_id" in the DB so I can FK them all back to the PK orders.order_id
I was provided with this script which did a great job:
SELECT t.name, c.name
FROM sys.tables t
JOIN sys.columns c ON t.object_id = c.object_id
WHERE c.name = 'order_id'
ORDER BY t.name, c.name
How would I modify this to add a column to tell me if the result c.name is already an FK back to my original table?