Tarzan
Tarzan

Reputation: 4538

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? I have seen documentation on how to do this at the column level but not at the table level.

Upvotes: 1

Views: 1721

Answers (3)

Pieczarr
Pieczarr

Reputation: 358

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.

Upvotes: 1

Ben Thul
Ben Thul

Reputation: 32707

I was able to do the following in 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

Upvotes: 3

DWright
DWright

Reputation: 9500

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)

Upvotes: 1

Related Questions