この例では、Key オブジェクトの DeleteRule プロパティの機能を示します。コードは、新しい Table を追加し、それに新しい主キーを定義し、DeleteRule に adRICascade を設定します。
DeleteRule Prop
Sub DeleteRuleX()
Dim kyPrimary As New ADOX.Key
Dim cat As New ADOX.Catalog
Dim tblNew As New ADOX.Table
' Connect the catalog
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"data source=c:\Program Files\" & _
"Microsoft Office\Office\Samples\Northwind.mdb;"
' Name new table
tblNew.Name = "NewTable"
' Append a numeric and a text field to new table.
tblNew.Columns.Append "NumField", adInteger, 20
tblNew.Columns.Append "TextField", adVarWChar, 20
' Append the new table
cat.Tables.Append tblNew
' Define the Primary key
kyPrimary.Name = "NumField"
kyPrimary.Type = adKeyPrimary
kyPrimary.RelatedTable = "Customers"
kyPrimary.Columns.Append "NumField"
kyPrimary.Columns("NumField").RelatedColumn = "CustomerId"
kyPrimary.DeleteRule = adRICascade
' Append the primary key
cat.Tables("NewTable").Keys.Append kyPrimary
''Delete the table as this is a demonstration
cat.Tables.Delete tblNew.Name
End Sub