ForeignKeyConstraint.DeleteRule 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當某列被刪除時,會取得或設定該限制中發生的動作。
public:
virtual property System::Data::Rule DeleteRule { System::Data::Rule get(); void set(System::Data::Rule value); };
public virtual System.Data.Rule DeleteRule { get; set; }
[System.Data.DataSysDescription("ForeignKeyConstraintDeleteRuleDescr")]
public virtual System.Data.Rule DeleteRule { get; set; }
member this.DeleteRule : System.Data.Rule with get, set
[<System.Data.DataSysDescription("ForeignKeyConstraintDeleteRuleDescr")>]
member this.DeleteRule : System.Data.Rule with get, set
Public Overridable Property DeleteRule As Rule
屬性值
這是其中一項 Rule 價值。 預設值為 Cascade。
- 屬性
範例
以下範例建立 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 fkConstraint As ForeignKeyConstraint
' Set parent and child column variables.
parentColumn = suppliersProducts.Tables("Suppliers").Columns("SupplierID")
childColumn = suppliersProducts.Tables("Products").Columns("SupplieriD")
fkConstraint = New ForeignKeyConstraint( _
"SuppierFKConstraint", parentColumn, childColumn)
' Set null values when a value is deleted.
fkConstraint.DeleteRule = Rule.SetNull
fkConstraint.UpdateRule = Rule.Cascade
fkConstraint.AcceptRejectRule = AcceptRejectRule.Cascade
' Add the constraint, and set EnforceConstraints to true.
suppliersProducts.Tables("Suppliers").Constraints.Add(fkConstraint)
suppliersProducts.EnforceConstraints = True
End Sub
備註
當某列從父資料表被刪除時,會 DeleteRule 決定子資料表(或多個資料表)欄位中會發生什麼事。 如果規則設為 Cascade,子列將會被刪除。
若設為 SetNull, DBNull 則 a 會被放置在受影響列的適當欄位中。 根據你的資料來源,欄位中可能允許或不允許 null 值。 例如,SQL Server 允許在主鍵欄位中找到多個空值,即使它們並非唯一。 然而,在 中 DataTable,若 DataColumn 物件 Unique 屬性設為 true,則主鍵欄位不允許多個空值。
若設為 SetDefault,則該欄位的預設值被指派。