SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to archive records with cyclic relationships


How to archive records with cyclic relationships

Author
Message
DataDog
DataDog
SSChasing Mays
SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)

Group: General Forum Members
Points: 611 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 ...
Evil Kraig F
Evil Kraig F
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19329 Visits: 7660
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
DataDog
DataDog
SSChasing Mays
SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)

Group: General Forum Members
Points: 611 Visits: 426
2 days 2 years 2 millenia won't make any difference as they are all linked in a chain!
Evil Kraig F
Evil Kraig F
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19329 Visits: 7660
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
DataDog
DataDog
SSChasing Mays
SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)

Group: General Forum Members
Points: 611 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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search