Solved

help with relationship constraints

Posted on 2014-10-09
1
114 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

691 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