> ## Content Index
> Fetch the complete content index at: https://blog.tsd.digital/llms.txt
> Use this file to discover other available public pages before exploring further.

# Deleting test orders and baskets from uCommerce
- URL: https://blog.tsd.digital/deleting-test-orders-and-baskets-from-ucommerce/
- Published: 2010-10-01T10:53:43.000Z
- Updated: 2010-10-01T10:53:43.000Z
- Author: Tim Gaunt
- Tags: Development, e-commerce, SQL, SQL Server, Ucommerce, Umbraco, #Import 2025-04-01 05:37

Although Søren has posted a helpful post on how to [delete entire purchase orders from the database here](http://www.publicvoid.dk/DeletingPurchaseOrdersAndBasketsFromTheDatabaseInUCommerce.aspx?ref=blog.tsd.digital), we needed something a little less “all or nothing” so put the below together.

## Delete a specific order id

\--Delete purchaseorders and associated data based on order id DECLARE @OrderNumber nvarchar(50) SET @OrderNumber = 'TEST-40' BEGIN TRAN UPDATE a SET ShipmentId = NULL FROM uCommerce\_OrderLine a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber UPDATE uCommerce\_PurchaseOrder SET BillingAddressId = NULL WHERE OrderNumber = @OrderNumber DELETE a FROM uCommerce\_Shipment a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber DELETE a FROM uCommerce\_OrderAddress a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber DELETE a FROM uCommerce\_OrderProperty a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber DELETE a FROM uCommerce\_OrderLine a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber DELETE a FROM uCommerce\_Payment a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber DELETE a FROM uCommerce\_OrderStatusAudit a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber DELETE FROM uCommerce\_PurchaseOrder WHERE OrderNumber = @OrderNumber --TODO: Expand this so it checks for other orders --DELETE a FROM uCommerce\_Address a INNER JOIN uCommerce\_PurchaseOrder b ON a.CustomerId = b.CustomerId WHERE b.OrderNumber = @OrderNumber --DELETE a FROM uCommerce\_Customer a INNER JOIN uCommerce\_PurchaseOrder b ON a.CustomerId = b.CustomerId WHERE b.OrderNumber = @OrderNumber --Uncomment this --COMMIT TRAN --And comment out this ROLLBACK TRAN

## Delete all baskets

\--Delete all carts purchaseorders and associated data BEGIN TRAN UPDATE a SET ShipmentId = NULL FROM uCommerce\_OrderLine a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE OrderNumber IS NULL UPDATE uCommerce\_PurchaseOrder SET BillingAddressId = NULL WHERE OrderNumber IS NULL DELETE a FROM uCommerce\_Shipment a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL DELETE a FROM uCommerce\_OrderAddress a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL DELETE a FROM uCommerce\_OrderProperty a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL DELETE a FROM uCommerce\_OrderLine a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL DELETE a FROM uCommerce\_Payment a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL DELETE a FROM uCommerce\_OrderStatusAudit a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL DELETE FROM uCommerce\_PurchaseOrder WHERE OrderNumber IS NULL --TODO: Expand this so it checks for other orders --DELETE a FROM uCommerce\_Address a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.NULL = @NULL --DELETE a FROM uCommerce\_Customer a INNER JOIN uCommerce\_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.NULL = @NULL --Uncomment this --COMMIT TRAN --And comment out this ROLLBACK TRAN

**Update:** At the request of Søren, I’ve altered the delete all baskets post so it allows you to delete all baskets older than a given date, see: [Delete all UCommerce baskets older than x days](http://blogs.thesitedoctor.co.uk/tim/2010/10/04/Delete+All+UCommerce+Baskets+Older+Than+X+Days.aspx?ref=blog.tsd.digital)