The Site Doctor Blog

Footprints in the snow of a warped mind

< Back to Blog

Delete all orders from Ucommerce

A while ago I blogged about how to delete test orders and baskets from Ucommerce and Delete all products and orders from Ucommerce which I frequently use.

As I often want to only clear out the orders as well so I thought it worth popping together a quick script to delete only the orders. This works on Ucommerce v9 and should work for older versions too but I've not tested it.

    BEGIN TRAN   
    DELETE FROM uCommerce_OrderLineDiscountRelation
    DELETE FROM uCommerce_ShipmentDiscountRelation
    DELETE FROM uCommerce_Discount
    UPDATE uCommerce_OrderLine SET ShipmentId = NULL
    UPDATE uCommerce_PurchaseOrder SET BillingAddressId = NULL
    DELETE FROM uCommerce_Shipment
    DELETE FROM uCommerce_OrderAddress
    DELETE FROM uCommerce_OrderProperty
    DELETE FROM uCommerce_OrderLine
    DELETE FROM uCommerce_PaymentProperty
    DELETE FROM uCommerce_Payment
    DELETE FROM uCommerce_OrderStatusAudit
    DELETE FROM uCommerce_PurchaseOrder
    DELETE FROM uCommerce_Address
    -- NOTE: Only needed if you use our Stripe package
    -- DELETE FROM uCommerce_StripeCustomer
    SELECT * FROM uCommerce_PurchaseOrder o
    ROLLBACK TRAN
    -- When happy it works, uncomment this line and comment out the ROLLBACK
    -- COMMIT TRAN
Author: Tim on

Liked this post? Got a suggestion? Leave a comment