Table.ForeignKeys 속성

Represents a collection of ForeignKey objects. Each ForeignKey object represents a foreign key defined on the table.

네임스페이스:  Microsoft.SqlServer.Management.Smo
어셈블리:  Microsoft.SqlServer.Smo(Microsoft.SqlServer.Smo.dll)

구문

‘선언
<SfcObjectAttribute(SfcContainerRelationship.ChildContainer, SfcContainerCardinality.ZeroToAny,  _
    GetType(ForeignKey), SfcObjectFlags.Design)> _
Public ReadOnly Property ForeignKeys As ForeignKeyCollection 
    Get
‘사용 방법
Dim instance As Table 
Dim value As ForeignKeyCollection 

value = instance.ForeignKeys
[SfcObjectAttribute(SfcContainerRelationship.ChildContainer, SfcContainerCardinality.ZeroToAny, 
    typeof(ForeignKey), SfcObjectFlags.Design)]
public ForeignKeyCollection ForeignKeys { get; }
[SfcObjectAttribute(SfcContainerRelationship::ChildContainer, SfcContainerCardinality::ZeroToAny, 
    typeof(ForeignKey), SfcObjectFlags::Design)]
public:
property ForeignKeyCollection^ ForeignKeys {
    ForeignKeyCollection^ get ();
}
[<SfcObjectAttribute(SfcContainerRelationship.ChildContainer, SfcContainerCardinality.ZeroToAny, 
    typeof(ForeignKey), SfcObjectFlags.Design)>]
member ForeignKeys : ForeignKeyCollection
function get ForeignKeys () : ForeignKeyCollection

속성 값

유형: Microsoft.SqlServer.Management.Smo.ForeignKeyCollection
A ForeignKey object that represents all the foreign keys defined on the table.

The following code example shows how to display each foreign key in the AdventureWorks2012 tables.

C#

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

Foreach (Table tb in db.Tables) 
{
   foreach (ForeignKey f in tb.ForeignKeys)
   {
      Console.WriteLine("The " + tb.Name + " table contains the " + f.ToString() + " foreign key.");
   }
}

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) 
{
   foreach ($f in $tb.ForeignKeys)
   {
      Write-Host "The" $tb.Name "table contains the" $f "foreign key."
   }
}

참고 항목

참조

Table 클래스

Microsoft.SqlServer.Management.Smo 네임스페이스

관련 자료

테이블

CREATE TABLE(Transact-SQL)