ForeignKeyConstraint クラスとは? わかりやすく解説

ForeignKeyConstraint クラス

値または行を削除または更新したときに、主キー外部キーリレーションシップ関係するセットに対して適用するアクション制約表します

名前空間: System.Data
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Class ForeignKeyConstraint
    Inherits Constraint
Dim instance As ForeignKeyConstraint
public class ForeignKeyConstraint : Constraint
public ref class ForeignKeyConstraint : public
 Constraint
public class ForeignKeyConstraint extends Constraint
public class ForeignKeyConstraint extends
 Constraint
解説解説

ForeignKeyConstraint は、列内の値を削除または更新したときに実行されるアクション制限します。この制約主キー列に使用する必要があります2 つテーブル間に親子リレーションシップがある場合は、親テーブルから値を削除したときに、子行が次のいずれか影響を受けることあります

ForeignKeyConstraint オブジェクトは DataTable の ConstraintCollection に格納されています。このコレクションアクセスするには Constraints プロパティ使用します

EnforceConstraints プロパティtrue設定されていない限り制約適用されません。

AcceptRejectRule は、DataTable オブジェクトの AcceptChanges メソッド呼び出されるたびに適用されます。

使用例使用例

ForeignKeyConstraint作成し、そのプロパティ一部設定し、これを DataTable オブジェクトConstraintCollection追加する例を次に示します

' The next line goes into the Declarations section of the module:
' SuppliersProducts is a class derived from DataSet.
Private suppliersProducts As SuppliersProducts

Private Sub CreateConstraint()
    ' Declare parent column and child column variables.
    Dim parentColumn As DataColumn
    Dim childColumn As DataColumn
    Dim fkeyConstraint As ForeignKeyConstraint

    ' Set parent and child column variables.
    parentColumn = suppliersProducts.Tables("Suppliers").Columns("SupplierID")
    childColumn = suppliersProducts.Tables("Products").Columns("SupplierID")
    fkeyConstraint = New ForeignKeyConstraint( _
        "SupplierFKConstraint", parentColumn, childColumn)

    ' Set null values when a value is deleted.
    fkeyConstraint.DeleteRule = Rule.SetNull
    fkeyConstraint.UpdateRule = Rule.Cascade
    fkeyConstraint.AcceptRejectRule = AcceptRejectRule.Cascade

    ' Add the constraint, and set EnforceConstraints to true.
    suppliersProducts.Tables("Products").Constraints.Add(fkeyConstraint)
    suppliersProducts.EnforceConstraints = True
End Sub
継承階層継承階層
System.Object
   System.Data.Constraint
    System.Data.ForeignKeyConstraint
スレッド セーフスレッド セーフ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ForeignKeyConstraint メンバ
System.Data 名前空間
AcceptRejectRule 列挙
DataTable クラス
ConstraintCollection クラス
Rule



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ForeignKeyConstraint クラス」の関連用語

ForeignKeyConstraint クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ForeignKeyConstraint クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS