SQL存储过程,请大家帮我解释一下
create procedure ordersadd
{
(@customerid int, @cartid nvarchar(50), @orderdate datetime, @shipdate datetime, @orderid int output)
as
begin tran addorder
insert into orders
(@customid,@orderdate,@shipdate)
select @orderid=@@identity
insert into orderdetails --这里有点不能理解,1
(orderid,bookid,quantity,unitcost)
select
@orderid,shoppingCart.book,quantity,books.unitcost
from
shoppingcart inner join books on shoppingcart.bookid=books.bookid
where
cartid=@cartid
exec shoppingcartempty @cartid --这里也有点不懂,2
commit tran addorder
}
不能理解1之前能看懂,用事务,先向orders表中加入数据,并获取自动增量的值到变量@orderid中,后面那个insert语句就看不懂了,为什么没有值呢??还有就是那个exec shoppingcartempty @cartid 是什么意思?,先谢谢大家帮我解决了