简体   繁体   English

如何使用SMO获取和设置SQL Server 2008表的description属性?

[英]How can I get and set the description property of a SQL Server 2008 table using SMO?

How can I get and set the description property of a SQL Server 2008 table using Microsoft.SqlServer.Management.Smo? 如何使用Microsoft.SqlServer.Management.Smo获取和设置SQL Server 2008表的description属性? I have seen documentation on how to do this at the column level but not at the table level. 我已经看到了有关如何在列级别执行此操作但不在表级别的文档。

I was able to do the following in powershell: 我能够在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

Can't remember: Is the description in the Extended Properties? 不记得了:扩展属性中的描述是什么? If so, TableViewTableTypeBase.ExtendedProperties will have your description for you (which Microsoft.SqlServer.Management.Smo.Table inherits) 如果是这样,TableViewTableTypeBase.ExtendedProperties将为您提供您的描述(Microsoft.SqlServer.Management.Smo.Table继承)

It is in extended properties, I do it this way: 它在扩展属性中,我这样做:

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

You need to specify which extended property you need in string - thats why you could not find it so easily. 您需要在字符串中指定所需的扩展属性 - 这就是为什么您无法轻易找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM