Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to archive records with cyclic relationships Expand / Collapse
Author
Message
Posted Monday, October 22, 2012 4:34 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, October 29, 2013 6:02 AM
Points: 147, Visits: 426
In my application a single "Shipment" can include "OrderItems" from multiple "Orders"

This creates a cyclic relationship in the database:

OrderItem belongs to Shipment which includes other OrderItems which belong to other Orders which have OrderItems in other Shipments

This creates the problem that I can not archive an Order without archiving its related Shipments
but I can't archive a Shipment without archiving its related Orders ...

... and due to the Orders and Shipments that exist in my business nothing can be archived!

If I archive Shipments first and only archive Orders when all directly related Shipments have already been archived
this means the application no longer reflects reality (Orders which have been shipped have no shipping information)

I could add an "Hidden" flag to "Orders" and alter the SQL to hide soon-to-be-archived records from the application completely

But I am now curious how others would approach this ...
Post #1375329
Posted Monday, October 22, 2012 10:26 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Monday, December 15, 2014 2:26 PM
Points: 5,466, Visits: 7,647
I personally only tend to archive data that's over 2 years old, so at that point the shipments involved and all orders SHOULD be filled. I'd put in some logic to make sure I got flagged if something went horribly awry in that plan though, and just make sure all involved items were both complete and over 2 years old, otherwise they'd wait for everything involved to age correctly.


- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1375598
Posted Monday, October 22, 2012 10:35 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, October 29, 2013 6:02 AM
Points: 147, Visits: 426
2 days 2 years 2 millenia won't make any difference as they are all linked in a chain!
Post #1375603
Posted Monday, October 22, 2012 11:10 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Monday, December 15, 2014 2:26 PM
Points: 5,466, Visits: 7,647
DataDog (10/22/2012)
2 days 2 years 2 millenia won't make any difference as they are all linked in a chain!


Eventually everything in a shipment/order would have to age past the 2 year mark, at which point I'd archive. Even though yes, they chain, at some point everything in some order and some shipment would have to get past 2 years.

If I needed another alternative, what I'd most likely end up doing is talking with business and finding out when they're unlikely to ever need shipment information again. Once an order archived, I'd copy the shipment header to the archive if it wasn't there and then move that order's pieces of the shipment over, removing them from the primary DB. Eventually a shipment would be empty in the primary and I'd remove the header, finally fully archiving it.

If neither of those work, then I'm missing something important about your data-design.



- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1375623
Posted Monday, October 22, 2012 11:37 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, October 29, 2013 6:02 AM
Points: 147, Visits: 426
Evil Kraig F (10/22/2012)
Eventually everything in a shipment/order would have to age past the 2 year mark, at which point I'd archive. Even though yes, they chain, at some point everything in some order and some shipment would have to get past 2 years.


Yes but they would always be linked to something less than 2 years old ...

Evil Kraig F (10/22/2012)
If I needed another alternative, what I'd most likely end up doing is talking with business and finding out when they're unlikely to ever need shipment information again. Once an order archived, I'd copy the shipment header to the archive if it wasn't there and then move that order's pieces of the shipment over, removing them from the primary DB. Eventually a shipment would be empty in the primary and I'd remove the header, finally fully archiving it.


Yes, that is what I will do

Unfortunately this impacts on the business rules so a careful redesign is required to ensure the application never sees a partially archived Order ...

Moral of the story: always design and test your archiving procedures before application goes live ... not all db designs allow for simple "follow the references" archiving
Post #1375637
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse