Solved

Foreign Key or no Foreign Key

Posted on 2011-03-16
3
321 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

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…
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
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

685 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