Works great, but...
I need to use it in a stored proc where it should look up the foreign keys from a twin DB, let's call it DB1 and create them in say, DB2.
Since switching database context in stored procs is not possible, I prefixed sys.foreign_keys with Db1, and likewise for the column select.
Tested the select statements, they produced what looked like correct results, but when I ran the entire statement, all I got was nulls.
Switched context to DB1, and it worked again.
I've been spinning my wheels on this all afternoon, but can't figure out what goes wrong.