做购物车系统时利用到得几个sqlserver 存储过程
坏蛋是怎样炼成的3曹三少,稳压二极管封装,君如陌上尘txt下载
即以游客身份登录网站时以cookie的方式存储购物车,而以登录用户的身份进入时将购物车信息存储到数据库中去,若是先以游客身份完成购物再登录继续购物,则将cookies购物车存入数据库;
其中涉及到的存储过程主要如下:
一:已登录会员添加商品到购物车功能:
/* @store_sum表示要添加的商品数量,添加同时确认购物车中自己已有的数量与将要加入的数量之和是否超过库存 */
create proc ncp_cart_add
(
@store_id int,
@store_sum int=1,
@member_id int
)
as
declare @amount int
declare @nowamount int
begin
select @amount=(select amount from ncp_store where id=@store_id)
if exists(select 1 from [ncp_cart] where store_id=@store_id and member_id=@member_id)
begin
select @nowamount=(select store_sum+@store_sum from ncp_cart where store_id=@store_id and member_id=@member_id)
if @nowamount>@amount
return 0
else
update [ncp_cart] set store_sum=store_sum+@store_sum,addtime=getdate() where store_id=@store_id and member_id=@member_id
return 1
end
else
begin
select @nowamount=(select store_sum from ncp_cart where store_id=@store_id and member_id=@member_id)
if @nowamount>@amount
return 0
else
insert into [ncp_cart](store_id,store_sum,member_id) values(@store_id,@store_sum,@member_id)
return 1
end
end
go
二:购物车的删除功能
/* type 为1是全部删 0时只删一个 */
create procedure ncp_cart_del
@type int=0,
@store_id int ,
@member_id int
as
begin
if @type=0
delete from [ncp_cart] where store_id=@store_id and member_id=@member_id
else
delete from [ncp_cart] where member_id=@member_id
end
go
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
sql某个日期是当年的第几周
/* *周一作为一周的开始 *当年的1月1号所在的周算作第一周 */ CREATE function GetWeekIndexFirstDate ( @...
[阅读全文]
-
-
数据库SQL---范式
1、数据冗余导致的问题:冗余存储、更新异常、插入异常、删除异常。 2、函数依赖:一种完整性约束。 在关系模式r(R)中,α属于R,β属于R。 1)α函数...
[阅读全文]
-
-
数据库SQL---查询
1、查询所有列 select *from emp;--*表示所有的,from emp表示从emp表中查询。 2、查询指定列 select empno,e...
[阅读全文]
-
-
-
-
-
网友评论