use ecommerce
go
ifexists(select 价格 from 商品信息表 where 价格 >'6000')select*from 商品信息表 where(价格 =any(select 价格
from 商品信息表 where 价格 >'6000'))elseprint'没有价格在6000元以上的商品'
go
在商品表中,查询某种商品,如果有,就修改该商品的名称,并输出商品的信息,否则输出“没有该商品!”
use ecommerce
go
ifexists(select 名称 from 商品信息表 where 名称 ='红米K40')beginupdate 商品信息表 set 名称 ='红米K40pro'where 名称 ='红米K40'select*from 商品信息表 where 名称 ='红米K40pro'endelseprint'没有该商品!'
go
查询商品购买信息,将商品的购买数量都加1。
use ecommerce
go
selectfrom 购买信息表
while(1)beginupdate 购买信息表 set 购买数量 = 购买数量 +1breakend
use ecommerce
go
createfunction GMSL(@订单号 nchar(10))returns@YYDStable(订单号 nchar(10), 商品名称 nchar(10), 购买数量 int)asbeginif(select 购买数量 from 购买信息表 where 订单号 = @订单号)>2insertinto@YYDSselect 订单号,商品名称,购买数量 from 购买信息表
where 订单号 = @订单号 and 购买数量 >2return;end
go
/*函数调用 订单号为 D002*/select*from GMSL('D002')