Table.Parent Property

 

Applies To: SQL Server 2016 Preview

Gets the Database object that is the parent of the Table object.

Namespace:   Microsoft.SqlServer.Management.Smo
Assembly:  Microsoft.SqlServer.Smo (in Microsoft.SqlServer.Smo.dll)

Syntax

[SfcObjectAttribute(SfcObjectRelationship.ParentObject, SfcObjectFlags.Design)]
public Database Parent { get; set; }
public:
[SfcObjectAttribute(SfcObjectRelationship::ParentObject, SfcObjectFlags::Design)]
property Database^ Parent {
    Database^ get();
    void set(Database^ value);
}
[<SfcObjectAttribute(SfcObjectRelationship.ParentObject, SfcObjectFlags.Design)>]
member Parent : Database with get, set
<SfcObjectAttribute(SfcObjectRelationship.ParentObject, SfcObjectFlags.Design)>
Public Property Parent As Database

Property Value

Type: Microsoft.SqlServer.Management.Smo.Database

A Database object value that is the parent of the Table object.

Examples

Legacy Code Example

The following code example prints the name of the parent database for each AdventureWorks2012 table.

C#

Server srv = new Server("(local)");
Database db = srv.Databases["AdventureWorks2012"];

foreach (Table tb in db.Tables) 
{
   Database pnt = tb.Parent;
   Console.WriteLine(pnt.Name);
}

Powershell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
$db = New-Object Microsoft.SqlServer.Management.Smo.Database
$db = $srv.Databases.Item("AdventureWorks2012")

Foreach ($tb in $db.Tables) 
{
   Write-Host $tb.Parent.Name
}

See Also

Table Class
Microsoft.SqlServer.Management.Smo Namespace

CREATE TABLE (Transact-SQL)
Unable to find linked topic '811e00f9-303f-42b5-8bd4-2cdb829c84e9'.

Return to top