create proc p6 @bianhao char(10) as deletefrom 雇员表 where 雇员编号[email protected] exec p6 'q1' select * from 雇员表
1
select * from ck
1 2 3 4 5 6
create proc p7 @chengshi char(20),@geshu intoutput as select @geshu=COUNT(仓库号) from ck where 城市[email protected]
1 2 3
declare @jieshou int exec p7 '珠海',@jieshou output print @jieshou
1 2 3 4 5
create proc p8 @ckhao char(10),@city char(10),@mianji float as insertinto ck values (@ckhao,@city,@mianji)
1
exec p8 'WH10','增城',1000
1
select * from ck
存储过程使用事务
实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
CreateProcedure MyProcedure AS Begin Set NOCOUNT ON; Set XACT_ABORT ON; begin tran ok --开始一个事务OK deletefrom rxqz where qz= 'rx015 '--删除数据 save tran bcd --保存一个事务点命名为bcd update sz setname='李丽s'wherename= '李丽'--修改数据 if @@error<>0--判断修改数据有没有出错 begin--如果出错 rollback tran bcd -- 回滚事务到BCD 的还原点 commit tran ok --提交事务 end else--没有出错 commit tran ok --提交事务 End