Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > General > Database Concepts & Design > Entity relationships - what's correct

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-04-07, 13:18
lfoulkrod lfoulkrod is offline
Registered User
 
Join Date: Oct 2007
Posts: 4
Entity relationships - what's correct

Let's say I have two entities, A and B that look like:

Entity A
--------
ID - int primary key
B_ID int foreign key references Entity B (ID)

Entity B
--------
ID - int primary key
A_ID int foreign key references Entity A (ID)

The relationship can be established either when you create or update entity A or create or update entity B.

My problem is that with this design, I have to know that when I update entity A to relate to entity B, I also have to update entity B to reflect this relationship. Same thing when I update entity B first.

Is there a better design strategy for this?
Reply With Quote
  #2 (permalink)  
Old 10-04-07, 13:45
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
Quote:
Originally Posted by lfoulkrod
Is there a better design strategy for this?
can't answer that question without knowing what you're trying to do

having A relate to B and also B relate to A is very, very unusual

perhaps you could either (1) tell us your real tables and columns, so that we could understand the relationships better, or (2) give examples of several rows of actual data so that we can understand the relationships better
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #3 (permalink)  
Old 10-04-07, 14:50
lfoulkrod lfoulkrod is offline
Registered User
 
Join Date: Oct 2007
Posts: 4
re: Entity relationships - what's correct

The real tables are types of assets, a computer for example. Table A represents a legacy asset, one that will be replaced by table B, the new asset. So they would look like:

Legacy Asset
-------------
LAID int primary key
Manufactuer
Model
etc...

New Asset
-----------
NAID int primary key
Manufacturer
Model
etc....

Now when you enter a new asset into the system you can associate it with a legacy asset, but the same is true for when you enter a legacy asset in the system, you can associate it to an existing new asset. The relationship between assets is one to one.
Reply With Quote
  #4 (permalink)  
Old 10-04-07, 15:05
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
Quote:
Originally Posted by lfoulkrod
The relationship between assets is one to one.
ah, well, that's okay then

__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #5 (permalink)  
Old 10-04-07, 15:09
lfoulkrod lfoulkrod is offline
Registered User
 
Join Date: Oct 2007
Posts: 4
It still seems kind of funky to me to have to update both tables when I create an association between the two entities. It seems more natural and less error prone to have the relationship defined in a single place. Right now it is:

LegacyAsset
------------
LAID int primary key
NAID int foreign key (NewAsset.NAID)

NewAsset
---------
NAID int primary key
LAID int foreign key (LegacyAsset.LAID)
Reply With Quote
  #6 (permalink)  
Old 10-04-07, 16:05
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 9,291
Quote:
Originally Posted by r937
ah, well, that's okay then
It doesn't get my stamp of approval. How do you ensure that the correct records are pointing at eachother? Can an asset be replaced by more than one asset? Can an asset replace more than one asset? For instance, a fax and a printer could be replaced by a single faxprinter. How would that be represented.
I do not think this is a good database design.
__________________
If it's not practically useful, then it's practically useless.

blindman
http://sqlblindman.googlepages.com/main
Reply With Quote
  #7 (permalink)  
Old 10-04-07, 16:11
lfoulkrod lfoulkrod is offline
Registered User
 
Join Date: Oct 2007
Posts: 4
The current requirements is that one asset is replaced by another single asset. A fax by a fax, a printer by a printer. I didn't think it was good database design, that's why I created this thread and asked for suggestions on the correct design, do you have any suggestions?
Reply With Quote
  #8 (permalink)  
Old 10-05-07, 06:30
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 4,874
My syggestion would be:

LegacyAsset
------------
LAID int primary key

NewAsset
---------
NAID int primary key
LAID int foreign key (LegacyAsset.LAID)

i.e. there is only one relationship, not two.

To query which new asset replaces old asset 123

Code:
select naid from newasset where laid=123;

To query which old asset was replaced by new asset 456

Code:
select laid from newasset where naid=456;

What more do you need?
__________________
Tony Andrews
http://tonyandrews.blogspot.com
Reply With Quote
  #9 (permalink)  
Old 10-05-07, 10:09
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 9,291
Quote:
Originally Posted by lfoulkrod
The current requirements is that one asset is replaced by another single asset. A fax by a fax, a printer by a printer. I didn't think it was good database design, that's why I created this thread and asked for suggestions on the correct design, do you have any suggestions?
I suggest you reevaluate your requirements, because that seems pretty ignorant of real-life business rules to me.
__________________
If it's not practically useful, then it's practically useless.

blindman
http://sqlblindman.googlepages.com/main
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On