mardi 5 mai 2015

How do I write a Stored Procedure to create a cart in a database?

Hi i want to eventually write code so that a user can add items to a shopping cart on my music website. Users should be able to add/delete items from their cart while logged in, the cart should not clear (even if user logs out) until the an order is placed. The cart table has a primary key set on (CartID, CustID)

From what I understand: 1st I want to create a cart for the particular user, This is the procedure I wrote to create cart, but i'm not sure if this is how I should do it, do I need to check if cart already exists? Is this a good way to create a cart?:

 CREATE PROCEDURE usp_Cart_create_cart
-- Add the parameters for the stored procedure here
(
@custID float
)
 AS
  BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
 insert into Cart (CartID, CustID)
 values (+1, @custID)
 END

Separate question: Can I create cart and add to cart all in one procedure?

Aucun commentaire:

Enregistrer un commentaire