创建关键字范例

目录

如下代码演示如何创建新的外部关键字。假定已存在两个表(Customers 和 Orders)。

Sub CreateKey()   Dim kyForeign As New ADOX.Key
   Dim cat As New ADOX.Catalog   cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=c:\Program Files\Microsoft Office\" & _
      "Office\Samples\Northwind.mdb;"   kyForeign.Name = "CustOrder"
   kyForeign.Type = adKeyForeign
   kyForeign.RelatedTable = "Customers"
   kyForeign.Columns.Append "CustomerId"
   kyForeign.Columns("CustomerId").RelatedColumn = "CustomerId"
   kyForeign.UpdateRule = adRICascade
   cat.Tables("Orders").Keys.Append kyForeignEnd Sub
www.51windows.Net