Solved

help with relationship constraints

Posted on 2014-10-09
1
105 Views
Last Modified: 2014-10-14
I'm hoping I can get some help with setting up my relationship constraints.  I am setting up my database which has an account table, bank table, contact table, address table and address type table (mailing, shipping, etc.) (see attached image).

I have a one-to-many relationship setup from bank to address type, account to address type and contact to address type and address to address type.  If you look at the foreign key relationship for the FK_AddressType_Account, the foreign key table is address type (ownerId column) and the primary/unique key table is account (Id column).  The owerId column in the address type can be a bank record, account record or contact record.  The problem is that an address has to be entered when adding a bank, account, or contact.  That should be able to be added on an insert or update.  So, what am I doing incorrectly that wouldn't allow data to be inserted?

10-9-2014-4-46-06-PM.jpg
Any help is appreciated.
Thank you.
0
Comment
Question by:-Dman100-
1 Comment
 
LVL 1

Accepted Solution

by:
nebb-tgr earned 500 total points
ID: 40372409
Hello.

The whole point of foreign key constraint is to:
- Verify that the number you put into this column actually exists in the foreign table.
- Not allow you to destroy data by removing data from other tables that are linked.

This means that you need the underlying data before you add a value into the foreign key column.

You can however allow nulls in that column.

AddressTypeId INT NULL FOREIGN KEY REFERENCES AddressType (Id)

Open in new window

0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question