Solved

Foreign Key or no Foreign Key

Posted on 2011-03-16
3
317 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
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now