ForeignKeyConstraint.DeleteRule Właściwość

Definicja

Pobiera lub ustawia akcję, która występuje w tym ograniczeniu po usunięciu wiersza.

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

Wartość właściwości

Jedna z Rule wartości. Wartość domyślna to Cascade.

Atrybuty

Przykłady

Poniższy przykład tworzy obiekt ForeignKeyConstraint, ustawia różne jego właściwości i dodaje go do DataTable obiektu 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

Uwagi

Po usunięciu wiersza z tabeli nadrzędnej określa, DeleteRule co się stanie w kolumnach tabeli podrzędnej (lub tabel). Jeśli reguła ma wartość Cascade, wiersze podrzędne zostaną usunięte.

Jeśli ustawiono wartość SetNull, element DBNull zostanie umieszczony w odpowiednich kolumnach wierszy, których dotyczy problem. W zależności od źródła danych wartość null może lub nie może być dozwolona w kolumnie. Na przykład SQL Server umożliwia odnalezienie wielu wartości null w kolumnie klucza podstawowego, nawet jeśli nie są unikatowe. DataTableJeśli jednak DataColumn właściwość obiektu jest ustawiona Unique na truewartość , wiele wartości null nie jest dozwolonych w kolumnach klucza podstawowego.

Jeśli ustawiono SetDefaultwartość na , zostanie przypisana wartość domyślna kolumny.

Dotyczy