HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to maintain referential integrity of an object graph when a node is deleted

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
howintegritygraphnodemaintaindeletedreferentialobjectwhen

Problem

In a relational database, if a node in an object graph is deleted, how can the object graph's referential integrity be maintained?

For example:

A product is deleted, how is the invoice containing the order which had a reference to the product kept relevant, in that the order may no longer be relevant. Moreover, how is the order kept relevant?

Solution

Suggestions:

  • Disallow deletion of a product that has been ordered.



  • Move the order detail row to an archive table that has no foreign key to products (perhaps denormalized to store product name etc that would otherwise be lost) then delete the product.



  • Move the product to an archive table and the order detail to another archive table with a foreign key reference to the product archive table.

Context

StackExchange Database Administrators Q#15686, answer score: 4

Revisions (0)

No revisions yet.