【问题标题】:How can I get and set the description property of a SQL Server 2008 table using SMO?如何使用 SMO 获取和设置 SQL Server 2008 表的描述属性?
【发布时间】:2013-01-21 22:48:38
【问题描述】:

如何使用 Microsoft.SqlServer.Management.Smo 获取和设置 SQL Server 2008 表的描述属性?我已经看到有关如何在列级别而不是表级别执行此操作的文档。

【问题讨论】:

    标签: c# sql-server smo


    【解决方案1】:

    我能够在 powershell 中执行以下操作:

    $s = new-object microsoft.sqlserver.management.smo.server '.';
    $db = $s.Databases['AdventureWorks2012'];
    $t = $db.Tables | where {$_.Name -eq 'Address'};
    $t.ExtendedProperties['MS_Description']; # will print current value
    $t.ExtendedProperties['MS_Description'].Value = 'new value';
    $t.ExtendedProperties['MS_Description'].Alter(); #persist the new value to the database
    

    【讨论】:

      【解决方案2】:

      不记得了:扩展属性中有描述吗?如果是这样,TableViewTableTypeBase.ExtendedProperties 将为您提供描述(Microsoft.SqlServer.Management.Smo.Table 继承)

      【讨论】:

      • 我遍历了所有的 ExtendedProperties,但在那里没有看到。
      • 这是一个我想的例子(希望这是你所追求的,不确定):msdn.microsoft.com/en-us/library/ms190243(v=sql.105).aspx。查找代码为 USE AdventureWorks2008R2; GO EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'Street address information for customers, employees, and vendors.', @level0type = N'SCHEMA', @level0name = Person, @level1type = N'TABLE', @level1name = Address; GO 的表的特定部分
      • 对,但它表明这确实是描述的地方。你可以在一个表上运行一个像 EXEC 这样的存储过程并查看扩展属性中的结果,然后尝试从 C#/SMO 端运行它。
      【解决方案3】:

      它在扩展属性中,我是这样做的:

      string Description = table.ExtendedProperties["MS_Description"].Value.ToString();
      

      你需要在字符串中指定你需要的扩展属性——这就是为什么你不能这么容易找到它的原因。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-31
        • 2016-05-28
        • 1970-01-01
        • 2023-03-11
        • 2016-08-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多