不带存储的存储过程的语法
create proc[edure] 存储过程名
as
sql语句
go --必须要加批处理的go
例子:
--创建不带参数的存储过程 use E_Market go --检测是否存在要创建的存储过程,如果存在将其删除 if exists(select * from sysobjects where name='usp_GetCommodityInfo') drop proc usp_GetCommodityInfo go --删除之后要加GO,因为create proc必须是批处理中仅有的语句 --题目 /* 创建存储过程——查看xiangxiang所购买的商品信息,要求包括用户名付款方式, 购买数量,商品名称,商品类别 */ create proc usp_GetCommodityInfo as select O.UserId as 用户号, PayWay as 付款方式, O.Amount as 购买数量,C.CommodityName as 商品名称, S.SortName as 类别名称 from OrderInfo as O inner join CommodityInfo as C on O.CommodityId=C.CommodityId inner join CommoditySort as S on C.SortId=S.SortId where O.UserId='xiangxiang' go --存储过程的结束 --如何使用不买参数的存储过程 exec usp_GetCommodityInfo go