Share via

Referential integrity in a split back end

Anonymous
2017-08-30T22:43:31+00:00

How do you enforce referential integrity when the parent record is in a table in one accdb (be_MainData.accdb) file and the child record is in a table in a different accdb file (be_SubData.accdb)?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

12 answers

Sort by: Most helpful
  1. Anonymous
    2017-08-31T01:32:47+00:00

    Scott, what you've shown implements Cascade Deletes, which is a good thing and is part of RI. But it's only a piece of the puzzle! You also need to check that deletions from a parent table don't leave orphan records in a child table, and error out the deletion if so; you need to ensure that adding, or changing the foreign key value, in a child record is only allowed with a valid parent record; and so on. It can all be done but the effort required really makes you appreciate a working RI system!

    KarenAnne, why the two backends? What benefit are you getting from the extra complication?

    Was this answer helpful?

    0 comments No comments
  2. ScottGem 68,830 Reputation points Volunteer Moderator
    2017-08-31T01:13:13+00:00

    There are many ways. As an example. Lets say you have a student database with a grades table. Now the student drops out so you want to delete his record and also his grades. So you have a delete student button. Behind the button you have code like:

    Dim strSQL as String

    strSQL = "DELETE * FROM tblGrades WHERE StudentID = " & Me.StudentID & ";"

    CurrentDB.Execute strSQL, dbFailOnError

    strSQL = "DELETE * FROM tblStudents WHERE StudentID = & Me.StudentID & ";"

    CurrentDB.Execute strSQL, dbFailOnError

    Me.Requery

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2017-08-30T23:49:03+00:00

    You can't, other than with VBA code in the data entry forms or with Before Insert Data Macros in the tables (and I'm not even sure if that will work). Referential integrity itself only applies within one database.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2017-08-30T23:48:21+00:00

    Hmm, can you give me a thought as to how I would attack this?

    Was this answer helpful?

    0 comments No comments
  5. ScottGem 68,830 Reputation points Volunteer Moderator
    2017-08-30T23:22:43+00:00

    You have to enforce RI through your user interface.

    Was this answer helpful?

    0 comments No comments