Solved

help with relationship constraints

Posted on 2014-10-09
1
111 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-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

737 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