Tabellen - Beziehungen löschen
Wie kann ich eine Beziehung löschen?
Wenn Sie eine Beziehung nicht mehr benötigen, können Sie diesen natürlich auch löschen. Beachten Sie aber, dass Referenzintegrität gegebenenfalls nicht mehr gewährleisten ist.
DAO-Variante
Beispiel:
Public Function DAO_DropRelation(pdbs As DAO.Database, _ psRelName As String) _ As Boolean On Error Resume Next pdbs.Relations.Delete psRelName DAO_DropRelation = (Err.Number = 0) End Function
ADOX-Variante
Beispiel:
Public Function ADO_DropRelation(pcnn As ADODB.Connection, _ ByVal psRelName As String, _ ByVal psFTable As String) As Boolean Dim S As String Dim cat As New ADOX.Catalog On Error Resume Next cat.ActiveConnection = pcnn ' Wichtig, hier muss die Sekundärtabelle ' angegeben werden cat.Tables(psFTable).Keys.Delete psRelName If Not cat Is Nothing Then Set cat = Nothing ADO_DropRelation = (Err.Number = 0) End Function
SQL-DDL-Variante
Beispiel:
' DAO-Variante Public Function DDL_DropRelationDao(pdbs As DAO.Database, _ psFTable As String, _ psRelName As String) _ As Boolean Dim sSQL As String On Error Resume Next sSQL = "ALTER TABLE " & psFTable sSQL = sSQL & " DROP CONSTRAINT " & psRelName pdbs.Execute sSQL, dbFailOnError DDL_DropRelationDao = (Err.Number = 0) End Function ' ADO-Variante Public Function DDL_DropRelationAdo(pcnn As ADODB.Connection, _ psFTable As String, _ psRelName As String) _ As Boolean Dim sSQL As String On Error Resume Next sSQL = "ALTER TABLE " & psFTable sSQL = sSQL & " DROP CONSTRAINT " & psRelName pcnn.Execute sSQL, dbFailOnError DDL_DropRelationAdo = (Err.Number = 0) End Function