This article explains how to remove old eCommerce basket entries by date. On commerce sites, users may create and leave multiple baskets. As a result, the database's basket table may grow very large, causing performance issues when logging into the site.
Backup the database before running any script against it.
- Backup the database.
- Copy the following text into sql:
declare @dt DateTime declare @Id bigint set @dt = '2014-01-01 00:00:00.000'; SELECT basket_id into #tmpBasketIds FROM basket where date_modified < @dt delete from basket_coupon_tbl where basket_id in(select basket_id from #tmpBasketIds) delete from basket_item where basket_id in(select basket_id from #tmpBasketIds) delete from basket where basket_id in(select basket_id from #tmpBasketIds) drop table #tmpBasketIds
- Change the dt variable to delete all baskets modified before that date.
- Execute the script on the database.
Please sign in to leave a comment.