Ejemplo de propiedades Type, RelatedColumn, RelatedTable y UpdateRule de clave, método Append de claves (VB)
En el código siguiente se muestra cómo crear una nueva relación de clave externa entre dos tablas existentes denominadas Customers y Orders.
' BeginCreateKeyVB
Sub Main()
On Error GoTo CreateKeyError
Dim kyForeign As New ADOX.Key
Dim cat As New ADOX.Catalog
' Connect to the catalog.
cat.ActiveConnection = "Provider='Microsoft.Jet.OLEDB.4.0';" & _
"Data Source='Northwind.mdb';"
' Define the foreign key.
kyForeign.Name = "CustOrder"
kyForeign.Type = adKeyForeign
kyForeign.RelatedTable = "Customers"
kyForeign.Columns.Append "CustomerId"
kyForeign.Columns("CustomerId").RelatedColumn = "CustomerId"
kyForeign.UpdateRule = adRICascade
' Append the foreign key to the keys collection.
cat.Tables("Orders").Keys.Append kyForeign
'Delete the key t demonstrate the Delete method.
cat.Tables("Orders").Keys.Delete kyForeign.Name
'Clean up.
Set cat.ActiveConnection = Nothing
Set cat = Nothing
Set kyForeign = Nothing
Exit Sub
CreateKeyError:
Set cat = Nothing
Set kyForeign = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
' EndCreateKeyVB
Consulte también
Append (método) (columnas ADOX)
Append (método) (claves ADOX)
Objeto Catalog (ADOX)
Objeto Column (ADOX)
Colección de columnas (ADOX)
Objeto Key (ADOX)
Colección de claves (ADOX)
Name (propiedad, ADOX)
RelatedColumn (propiedad, ADOX)
RelatedTable (propiedad, ADOX)
Objeto Table (ADOX)
Colección de tablas (ADOX)
Type (propiedad, clave, ADOX)
UpdateRule (propiedad, ADOX)
Comentarios
https://aka.ms/ContentUserFeedback.
Próximamente: A lo largo de 2024 iremos eliminando gradualmente GitHub Issues como mecanismo de comentarios sobre el contenido y lo sustituiremos por un nuevo sistema de comentarios. Para más información, vea:Enviar y ver comentarios de