473,771 Members | 2,347 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

1:1 Relationships: RI Enforcement/Cascading Deletes?

Seems like when there's a 1:1 relationship, the order of referential integrity
enforcement depends on which way you drag the mouse pointer when drawing the
relationship line.

If you drag from tblObject to tblCollection, a tblObject record must exist
before a tblCollection record can be created and if a tblObject record is
deleted, a like-keyed rec in tblCollection will get the cascade delete.

OTOH, if a record in tblCollection is deleted, an orphan is left in
tblCollection.

Personally, I'd avoid 1:1 relationships, but I'm dancing to somebody else's tune
on this project. Somebody decided it was so important that they needed to bring
in a data architecture specialist....w ild and crazy guys that they are....trying
to develop to their architecture is, shall we say, "challengin g".

On one hand, I keep telling myself that these people have forgotten more than
I'll ever know about "real" database design. On the other hand a little voice
says "JET is different - no triggers....RAD is different - we're in a hurry..."

Am I doing something wrong (besides having a 1:1 relationship)?

Workarounds?
--
PeteCresswell
Nov 12 '05 #1
9 3430
And your question is...?

- Turtle

"(Pete Cresswell)" <x@y.z> wrote in message
news:c8******** *************** *********@4ax.c om...
Seems like when there's a 1:1 relationship, the order of referential integrity enforcement depends on which way you drag the mouse pointer when drawing the relationship line.

If you drag from tblObject to tblCollection, a tblObject record must exist
before a tblCollection record can be created and if a tblObject record is
deleted, a like-keyed rec in tblCollection will get the cascade delete.

OTOH, if a record in tblCollection is deleted, an orphan is left in
tblCollection.

Personally, I'd avoid 1:1 relationships, but I'm dancing to somebody else's tune on this project. Somebody decided it was so important that they needed to bring in a data architecture specialist....w ild and crazy guys that they are....trying to develop to their architecture is, shall we say, "challengin g".

On one hand, I keep telling myself that these people have forgotten more than I'll ever know about "real" database design. On the other hand a little voice says "JET is different - no triggers....RAD is different - we're in a hurry..."
Am I doing something wrong (besides having a 1:1 relationship)?

Workarounds?
--
PeteCresswell

Nov 12 '05 #2
RE/
And your question is...?


How to enforce referential integrity and cascading deletes in both directions
when a 1:1 relatinship exists?

i.e. Table1 ===== Table2

Delete a rec from Table1, corresponding record in Table2 is deleted
automatically.

Delete a rec from Table2, corresponding record in Table1 is deleted
automatically.

Seems like either one can happen, but not both.
--
PeteCresswell
Nov 12 '05 #3
You wouldn't really want to enforce referential integrity in both
directions -
unless you never want to add any records.
If a record can't be added to Table2 unless there's a corresponding one in
Table1, and also vice versa, you can't add to either one.

So you choose one table as the Master Table, and enforce RI with deletes
from it to the Child Table.
Now look carefully at the data in the two tables and consider if you really
need to delete from the Master Table if there's no Child data.
For example, suppose the Master Table has the customer name and the
Child Table has the mailing address. (Admittedly, not a particularly
brilliant example.) If you don't have the mailing address, or know it has
changed and you don't have the new one, you might delete that record to
prevent anyone using outdated information, but that doesn't necessarily mean
that you'd need to delete the customer entirely.
If you do come to the conclusion that deleting a Child record really
does require deleting the record in the Master Table, you may want to
provide for that delete with explicit coding. Or you might be able to do it
by basing your form on a query which uses both tables.

HTH
- Turtle

"(Pete Cresswell)" <x@y.z> wrote in message
news:0l******** *************** *********@4ax.c om...
RE/
And your question is...?
How to enforce referential integrity and cascading deletes in both

directions when a 1:1 relatinship exists?

i.e. Table1 ===== Table2

Delete a rec from Table1, corresponding record in Table2 is deleted
automatically.

Delete a rec from Table2, corresponding record in Table1 is deleted
automatically.

Seems like either one can happen, but not both.
--
PeteCresswell

Nov 12 '05 #4
Yes, Pete. Even 1:1 relationships have a primary table and a related table.
The direction of the cascading delete is from the 1 to the many.

You could drag a 2nd copy of Table2 into the Relationships window, and try
creating another relationship between Table2.ID and Table1.ID where Table2
is the primary table? Never tried, but JET probably won't come at it. If it
did you may well have confused the life out of it, so you better do some
serious testing. Amongst other things, you probably would not be able to add
new records to such a design, since the primary record would be required in
both tables before it could be created in either.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"(Pete Cresswell)" <x@y.z> wrote in message
news:0l******** *************** *********@4ax.c om...
RE/
And your question is...?
How to enforce referential integrity and cascading deletes in both

directions when a 1:1 relatinship exists?

i.e. Table1 ===== Table2

Delete a rec from Table1, corresponding record in Table2 is deleted
automatically.

Delete a rec from Table2, corresponding record in Table1 is deleted
automatically.

Seems like either one can happen, but not both.
--
PeteCresswell

Nov 12 '05 #5

"Allen Browne" <Al*********@Se eSig.Invalid> wrote in message
news:3f******** **************@ freenews.iinet. net.au...
Yes, Pete. Even 1:1 relationships have a primary table and a related table. The direction of the cascading delete is from the 1 to the many.
*************** **
The above statement is very important . . if you really think that a delete
should work both ways then IMHO you data design is screwed . . if your
designers came up with such a structure I would certainly question their
reasoning . . and I was designing DBs in the 70s . . so normalising tables
etc, I do in my sleep . . grin . . . and JET is an excellent engine for
most applications when you know how to really design tables for it . .
usually the better the table design . . the easier the forms/code etc that
come s after it . .

as for 1:1 relationships . . there should be 1 ( ONE ) table that is the
master or primary entity. any other tables related to it are sub-sets of
data and need a very good reason to be seperated from the master. Security
is one good reason. Sensitive data can be stored seprately. Also data that
only occurs in reletively few records, but even this is not a strong reason
.. Or if some data is only rarely needed . and kept seperate for
performance reasons . . .

Ultimately anytime a 1:1 relationship occurs . . consider combining it and
demand a strong reason not to !!!

cheers paul g
ps . . my observations of questions in this newsgroup tell me that far too
many people are focused on clever code and not on underlying and less
glamourous table design . . if they thought out the application spec before
the built their systems they would avoid many of the silly ( read stupidly
unnessasry) problems that get posted here . .

*************** *****
You could drag a 2nd copy of Table2 into the Relationships window, and try
creating another relationship between Table2.ID and Table1.ID where Table2
is the primary table? Never tried, but JET probably won't come at it. If it did you may well have confused the life out of it, so you better do some
serious testing. Amongst other things, you probably would not be able to add new records to such a design, since the primary record would be required in both tables before it could be created in either.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"(Pete Cresswell)" <x@y.z> wrote in message
news:0l******** *************** *********@4ax.c om...
RE/
And your question is...?


How to enforce referential integrity and cascading deletes in both

directions
when a 1:1 relatinship exists?

i.e. Table1 ===== Table2

Delete a rec from Table1, corresponding record in Table2 is deleted
automatically.

Delete a rec from Table2, corresponding record in Table1 is deleted
automatically.

Seems like either one can happen, but not both.
--
PeteCresswell


Nov 12 '05 #6
RE/
The above statement is very important . . if you really think that a delete
should work both ways then IMHO you data design is screwed . . if your
designers came up with such a structure I would certainly question their
reasoning . .


I think this is going to be a blessing in disguise: a concrete technical reason
to depart from these guys' architecture. No bruised egos, just a different
requirement because the design isn't for the "real" databases they're used to.

As far as I can see, the departure wouldn't be any change in the logical
archicture - only physical.

What they're doing is using an "Object" table as a middleman for two other
tables - which lets them make some link tables do double duty.

e.g.
Element-->Object-->ObjectCommen t-->Comment
Collection-->Object-->ObjectCommen t-->Comment

All I'd do is add a second set of link tables.

viz:
Element-->ElementComme nt-->Comment
Collection-->CollectionComm ent-->Comment
I can't see any function that "Object" is peforming except to make the diagram
have less tables on it - i.e. look prettier. OTOH, it requires extra code and
has to use more MIPs when retrieving data.
--
PeteCresswell
Nov 12 '05 #7
x@y.z ((Pete Cresswell)) wrote in
<0l************ *************** *****@4ax.com>:
RE/
And your question is...?


How to enforce referential integrity and cascading deletes in both
directions when a 1:1 relatinship exists?

i.e. Table1 ===== Table2

Delete a rec from Table1, corresponding record in Table2 is
deleted automatically.

Delete a rec from Table2, corresponding record in Table1 is
deleted automatically.

Seems like either one can happen, but not both.


There is no logical relation that would work the way you describe,
so far as I can imagine.

I can't think of a use for 1:1 relationships that is not some form
of main type/sub type relationship, so there is, by definition, one
main table, with the parent record, and child records, even though
they are 1:1.

A 1:1 where both tables are "parents" makes no sense to me at all,
and sounds to me like two independent entities, or duplication that
belongs in a single table in the first place.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #8
ma********@nosp am.com (MacDermott) wrote in
<uV************ ****@newsread1. news.atl.earthl ink.net>:
You wouldn't really want to enforce referential integrity in both
directions -
unless you never want to add any records.


Well, it all depends on what you use for your join.

If each table has its own AutoNumber PK, and a foreign key pointing
to the other table, that foreign key can be non-required, so you
could add records with blank foreign key. Yet, once populated, you
could have a cascade delete relationship. Since you're dealing with
two different foreign keys, seems you could define it the way Pete
described (to my surprise!), but I still can't see *why* you'd do
this!

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #9
RE/
A 1:1 where both tables are "parents" makes no sense to me at all,
and sounds to me like two independent entities, or duplication that
belongs in a single table in the first place.


To use technical terminology: I think it's wacked too.

Snip FromPrevious post:
----------------------
What they're doing is using an "Object" table as a middleman for two other
tables - which lets them make some link tables do double duty.

e.g.
Element-->Object-->ObjectCommen t-->Comment
Collection-->Object-->ObjectCommen t-->Comment

All I'd do is add a second set of link tables.

viz:
Element-->ElementComme nt-->Comment
Collection-->CollectionComm ent-->Comment

I can't see any function that "Object" is peforming except to make the diagram
have less tables on it - i.e. look prettier. OTOH, it requires extra code and
has to use more MIPs when retrieving data.
-------------------------
--
PeteCresswell
Nov 12 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
7015
by: Matthew Wells | last post by:
I'm using this code to delete all relationships in my mdb file iFlag = 1 Do While iFlag <> 0 iFlag = 0 For Each rel In db.Relations db.Relations.Delete rel.Name iFlag = 1 Next rel Loop
49
2254
by: Mal | last post by:
Hi, As I gain knowledge through a lot of trial, error, and usenet posts.. I have a potentially odd question. I am using a commercial access application. It is a front-end / back end....multi-user app. with a lot of complex functionality (as you would expect from a commercial app). It doesn't have any relationships though.....is this odd???
3
11734
by: GGerard | last post by:
Hello Does anyone know if it is possible with Access 2000 to create relationships between tables using code? Thanks G.Gerard
1
2587
by: Gandalf | last post by:
I'm creating relationships between tables using VBA and ADOX. I can create one-to-one relationships with an inner join, but I can't figure out how to create these relationships with an outer join (specifically a left outer join). I'm including the code that creates the relationships with the inner join. Any help or suggestions would be greatly appreciated. Thanks! <----- CODE FOLLOWS ----->
3
1795
by: paulwilliamsonremove | last post by:
Hi, I have been manually setting up relationships in Access 2003. I received an error message when leaving a form that told me the record could not be saved because I had to have a related record in another ( child) table. After researching the problem, I decided to open up the table relationship manager and selected the "Show All" option.
5
1220
by: MLH | last post by:
I have two tables with a 1 to many relationship between the parent table and the child table. The parent table is tblOwners and contains vehicle owner records. The child table is tblVehicleJobs and contains records of towed vehicles that belong to the owners in tblOwners. Trouble is, towing company does not always know the ownership info when towing a vehicle into the shop. So, its impossible to enter the owner until after-the-fact when...
45
3423
by: salad | last post by:
I'm curious about your opinion on setting relationships. When I designed my first app in Access I'd go to Tools/Relationships and set the relationships. Over time I'd go into the window and see relationship spaghetti....tables/queries all overthe place with lots of relationship lines between here and there. After that first app I didn't do relationships. If I had a query, I defined the relationship. Many of the times when I create a...
1
2529
by: cesar.guinovart | last post by:
I have the following table CREATE TABLE ( int IDENTITY(1,1) CONSTRAINT PK_tbl_Items__item_id PRIMARY KEY, int DEFAULT(NULL) CONSTRAINT FK_tbl_Items__item_id__parent_id REFERENCES ( ) ON DELETE NO ACTION ON UPDATE NO ACTION )
4
4386
by: netnewbie78 | last post by:
Hello All, I don't have a problem (but maybe I will after I explain). I have a question with regards to something I saw in Access 2007. But first, a little backstory: I'm writing a very small stock database. For now, it will simply track what products come in (Stocks bought by Project) and what products go out (Stocks sold to by Project) . There are three tables: Products, Transactions and Projects.
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.