【问题标题】:Get Reference of ForeignKey by SMO通过 SMO 获取 ForeignKey 的参考
【发布时间】:2012-07-16 11:13:52
【问题描述】:

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

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")
  }
}

我找到了this one,但这个链接一开始是Foreignkeys,有什么方法可以在这里找到参考(意思是Column类型)?在这种情况下您有什么建议?

【问题讨论】:

    标签: c# sql-server c#-4.0 smo


    【解决方案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
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-02-09
      • 1970-01-01
      • 2013-10-17
      • 2020-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-26
      • 2015-12-29
      相关资源
      最近更新 更多