I have an small question I didn’t found an answer yet: how do I get in c# and using Microsoft.SqlServer.Smo the table a foreign key column is referring to?
foreach (Column column in currentTable.Columns) { if (column.IsForeignKey) { //GET TABLE FOREIGN KEY REFERS TO } }
You should start from the table itself, and enumerate all of it’s foreign keys. Sample code:
EDIT: Small change. In second foreach loop use foreach (ForeignKeyColumn column in key.Columns) (I had it foreach (Column column in key.Columns) before, and that’s wrong. My mistake.)