D
David W. Fenton
I'm revising the schema for an app I've just taken over and most of
the N:N tables don't have unique indexes defined on the pair of
foreign keys (so they have lots of duplicate records), but the FK
relationships are all set as CASCADE DELETE (and, unnecessarily,
CASCADE UPDATE, since all the FKs values are from Autonumber fields,
which can't be updated, of course).
Anyway, my tendency is to *not* set CASCADE DELETE on join tables,
because I'm never quite sure if the way *I* see the hierarchy is the
way Jet sees it. That is, I may think that something is the parent,
but Jet sometimes sees it as the child (e.g., lookup tables seem
subordinate to the main table, but they are actually the parent
tables if you define relationships for them, which I very often
don't, as a matter of fact).
Obviously, if one of the two parents of the N:N record is deleted,
then the join record is invalidated, but should I prevent that?
Or is the answer "it depends"?
In the present case, I'm included to cascade the deletions because
in the tables I'm working with, it would be OK to lose the record.
On the other hand, neither of the parents should be deleted, but if
they are, it would be easier to have the cleanup at the db engine
level.
I haven't yet decided if I want to allow these parents to be deleted
if they have children. In the past, the app has certainly been used
in that way (and that has resulted in a lot of orphan records
because RI was not enforced), but I'm not certain it should be in
the future.
Thoughts?
the N:N tables don't have unique indexes defined on the pair of
foreign keys (so they have lots of duplicate records), but the FK
relationships are all set as CASCADE DELETE (and, unnecessarily,
CASCADE UPDATE, since all the FKs values are from Autonumber fields,
which can't be updated, of course).
Anyway, my tendency is to *not* set CASCADE DELETE on join tables,
because I'm never quite sure if the way *I* see the hierarchy is the
way Jet sees it. That is, I may think that something is the parent,
but Jet sometimes sees it as the child (e.g., lookup tables seem
subordinate to the main table, but they are actually the parent
tables if you define relationships for them, which I very often
don't, as a matter of fact).
Obviously, if one of the two parents of the N:N record is deleted,
then the join record is invalidated, but should I prevent that?
Or is the answer "it depends"?
In the present case, I'm included to cascade the deletions because
in the tables I'm working with, it would be OK to lose the record.
On the other hand, neither of the parents should be deleted, but if
they are, it would be easier to have the cleanup at the db engine
level.
I haven't yet decided if I want to allow these parents to be deleted
if they have children. In the past, the app has certainly been used
in that way (and that has resulted in a lot of orphan records
because RI was not enforced), but I'm not certain it should be in
the future.
Thoughts?