"usp_ShoppingCartRemoveAbandoned" Stored Procedure

Description:

This stored procedure is run nightly by a scheduled SQL job called "RemoveAbandonedCarts." It deletes all entries in the ShoppingCart table that are more than one day old.  Since the items in a shopping cart are move to the Orders and OrderDetails tables when an order is placed, only abandoned carts are removed.

Definition:
CREATE Procedure usp_ShoppingCartRemoveAbandoned

AS

DELETE FROM Sales.ShoppingCartItem
WHERE 
    DATEDIFF(dd, DateCreated, GetDate()) > 30;

Database Tables Used:

ShoppingCartItem:   The ShoppingCartItem table keeps track of the items a user has purchased.  Its primary key is the ShoppingCartItemID field.  The ShoppingCartID is a string which is used to identify the user who owns the basket of items.  There is a many to one relationship between the ShoppingCartItem table and the Product table.  Note that if not Quantity is supplied, a default of 1 is entered.