Solved

Foreign Key or no Foreign Key

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

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…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
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.

789 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