This is the problem I am facing:
I have a table with several foreign keys. One of them does not get scripted when I script the table as Create To New Query window in SSMS but the rest of them do. It also doesn't appear in Keys folder in Object Explorer.
The only way it appears is when I open Design View for the table in SSMS, right-click on Design window and select Relationships. Then it shows up as expected (together with the rest of the foreign keys).
I am fairly confident I created this key via SSMS Design wizard.
The reason it came to my attention is that I ran Database Schema Compare in Visual Studio 2015 to deploy my changes and it didn't show this as a difference either (Design in Visual Studio doesn't show it, same for scripting the table Visual Studio). However, I remembered setting up this foreign key and looked into this to find that something is not quite right with it.
How can this be explained/avoided?
yes, when I script the other table foreign key I am looking for gets scripted
That is the answer. The FK exists on the other table. Not the table you are looking at. That's why it doesn't get scripted.