Solved

Foreign Key or no Foreign Key

Posted on 2011-03-16
3
322 Views
Last Modified: 2012-05-11
I am setting up a database where I will need to allow the user to delete records in a table that relates to a second one in a one to many relationship.  However, the table that is the 'one' table  holds data that can be deleted but the client wants to be able to save the 'many' table records for historical reporting.  Settiing up a Foreign Key in the 'many' table will cause an error when the record in the 'one' table is deleted.  I have tried to set up the tables different ways to avoid this relationship but it is what it is.  The only solution I know is to handle the relationship as needed in code but is there a better way?  
0
Comment
Question by:McGurk1
[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
3 Comments
 
LVL 9

Accepted Solution

by:
AriMc earned 500 total points
ID: 35150799
You could set the referencing column value to null before deleting the row it refers to.

0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 35150848
Generally speaking a historical table will not require references to any external tables and doesn't need foreign keys.
0
 

Author Comment

by:McGurk1
ID: 35150890
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

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.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

734 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