Database Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesDatabase Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 5th, 2009, 11:03 PM
blparker blparker is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 1 blparker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 57 sec
Reputation Power: 0
Efficient relationships?

Hey guys, I have a quick design problem that I need assistance with. I've been tasked (along with others) to redesign the central database that drives our organization. We basically have everything under control except for one aspect. To give you a brief overview, I have included a short summary of the issue below:

The issue revolves around the relationship between a demographic and address table. The demographic table contains such data as DemoID, FirstName, LastName, MaidenName, DOB, SSN, etc. The address table contains such data as AddrID, Address, City, State, Zip, etc. One requirement was to constrain a one-to-one relationship between the address and the demographic. Basically, each demographic record (person) may have one and only one physical address.

This works great by just including the AddrID in the corresponding demographic record. However, an issue arrives when we need to relate additional addresses to that demographic record. I know it sounds kind of confusing, but I’ll try to elaborate. Basically, each demographic record has ONE well-known, good address. But some of the applications that are developed around the database need additional addresses for information such as business addresses, and a few others. We would still like to capture these addresses in the same address table but we’re not sure how to enforce a one-to-one relationship between the demographic record and the ONE well-known, good address, while at the same time allowing the demographic records to have multiple addresses for other application specific information.

A few ideas that we came up with (all of which do not work) are:

1) Enforces a one-to-one relationship by including the AddrID foreign key, but can't differentiate between the ONE-known good address and other addresses.
Code:
+---------------+      +---------------+
|  Demographic  |      |    Address    |
+---------------+      +---------------+
|  PK, DemoID   |	|  PK, AddrID   |
|  FK, AddrID   |------|  Address      |
|  etc.         |1    1|  etc.         |
+---------------+      +---------------+


2) Allows for multiple addresses, but loses one-to-one relationship between one demographic record and one address record.
Code:
+---------------+       +---------------+        +---------------+
|  Demographic  |       | DemoAddr_Assn |        |    Address    |
+---------------+       +---------------+        +---------------+
|  PK, DemoID   |-------|  DemoID       |--------|  PK, AddrID   |
|  FK, AddrID   |N     N|  AddrID       |N      N|  Address      |
|  etc.         |       +---------------+        |  etc.         |
+---------------+                                +---------------+

3) A controversial design that will include the ONE-known good address in the demographic record and then allow the many to many relationship to allow multiple addresses for demographic records.
Code:
+---------------+       +---------------+        +---------------+
|  Demographic  |       | DemoAddr_Assn |        |    Address    |
+---------------+       +---------------+        +---------------+
|  PK, DemoID   |-------|  DemoID       |--------|  PK, AddrID   |
|  Address      |N     N|  AddrID       |N      N|  Address      |
|  City         |       +---------------+        |  etc.         |
|  State        |                                +---------------+
|  Zip          |
+---------------+


As you can see, there are problems with these designs, but I'm not sure which one of these (or none at all) would be the best design for the above requirements. Open to any and all suggestions. I know the length of this question is long, but any help would be tremendously appreciated. Thanks in advance.

blparker

Reply With Quote
  #2  
Old January 29th, 2009, 01:23 AM
dykebert's Avatar
dykebert dykebert is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 408 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 20 h 27 m 28 sec
Reputation Power: 2
The solution depends a lot on reporting perfromance and where you want to keep your business logic.

BTW According to what you posted, there's no difference between Option 2 and option 3 since you still have the FK AddrID in the demographic table.

Option 2 is the easiest to code and maintain since ALL addresses end up in the same table you do not need to do anything special.

There are 2+ versions of Option 2 .

The first (2A) is exactly what you have with both a FK in the Demographic table and an Association table.

The second option (2B) is to remove the FK from the Demographic table and Add a Primary_Flag column to the Association table. So you have this:

Demographic
PK, DemoID
etc

DemoAddr_Assn
DemoID
AddrID
PrimaryFlag - Set to True for the required address and false otherwise.

Of course as soon as you implement option 2B you'll want to know what the other address really are. So the typical design is: (2B+)

DemoAddr_Assn
DemoID
AddrID
AddrTypeID

AddrType
AddrTypeID
AddrType - (Primary, Mailing, Billing, Shipping, etc)


The key Advantage of option 2A is retrieval performance. This requires a bit more processing when you enter an address since you need to check if the FK field in the Demographic table is populated and then what happens if the FK address is actually the wrong one?

The key advantage of the 2B options is maitenenace. It is very easy to add or re-task addresses. However you do need to add code to make sure that at least one record exists in the association table.

If you decide on either of the 2B options you will want to create a stored query (view) that gives you the Primary address.

Hope this helps.
__________________
P.S. I am looking for work. <grin>.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesDatabase Development > Efficient relationships?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek