Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

Table.EnumForeignKeys Method

Enumerates a list of primary keys in which the table is referenced as a foreign key.

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

Return Value

Type: System.Data.DataTable
A DataTable system object value that contains a list of information about where this table is referenced as a foreign key. The table describes the different columns of the returned DataTable.

Column

Data type

Description

Table_Schema

String

The name of the schema associated with the table that contains the foreign key.

Table_Name

String

The name of the table that contains the foreign key.

Name

String

The name of the foreign key.

The following code example demonstrates how to enumerate a list of the primary keys that reference the table as a foreign key.

C#

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

foreach (Table tb in db.Tables)
{
   tb.EnumForeignKeys();
}

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)
{
   $tb.EnumForeignKeys()
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.