1

我想收集有关特定表的信息,所以这是我的代码:

StringBuilder sb = new StringBuilder();
sb.AppendLine();
ServerConnection conn = new ServerConnection();
conn.ConnectionString = "";//MyConnection string
Server srv = new Server(conn);
Database db = srv.Databases["MyDataBase"];
Table tb = db.Tables["MyTable"];
foreach(Column c in tb.Columns) {

   sb.AppendLine(c.Name + " -> " + c.DataType.ToString());
   sb.AppendLine(c.ExtendedProperties["MS_Description"].Value.ToString());

  if(c.IsForeignKey){

    //Need to get reference here:
    //Sb.AppendLine("ReferenceColumn")
    //Sb.AppendLine("ReferenceTable")
    //Sb.AppendLine("ReferenceSchema")
  }
}

我找到了这个,但是这个链接Foreignkeys首先得到了,有没有办法在这里找到参考(按Column类型)?在这种情况下你有什么建议?

4

1 回答 1

1

不确定这是否是您要找的东西!

foreach (ForeignKey FKey in currentTable.ForeignKeys)
{
    foreach (ForeignKeyColumn FKColumn in FKey.Columns)
    {
        //Hope this is what you are looking for!
        //Check the output of FKColumn.Name
        //Check the output of FKey.ReferencedTable
    }
}
于 2012-07-16T13:09:25.947 回答