select * from shop5_xs
select * from shop3_jb

declare @id int,@sale float,@quan int,@ywid int
set @id=5
set @sale=700
set @quan=3
set @ywid=4

begin tran
insert into shop5_xs values(@id,@sale,@quan,GETDATE(),@ywid)
if(@@ERROR!=0)
begin
rollback tran
print'插入失败'
return
end

else
begin
update shop3_jb set stock=stock-@quan where id=@id

if(@@ROWCOUNT=0)
begin
rollback tran
print'修改失败'
return
end

else
begin
commit tran
print'提交成功'
end
end

select * from shop3_jb
select * from shop5_xs

declare @id int,@sale float,@ywid int,@quan int
set @id=6
set @sale=1200
set @quan=100
set @ywid=2

begin tran
insert into shop5_xs values(@id,@sale,@quan,getdate(),@ywid)
save tran aaa
insert into shop5_xs values(@id,@sale,@quan,getdate(),@ywid)
if(@@ERROR!=0)
begin
rollback tran aaa
print'插入失败'
return
end
else
begin
update shop3_jb set stock=stock-@quan where id=@id
if(@@ROWCOUNT=0)
begin
rollback tran aaa
print'修改失败'
return
end
else
begin
commit tran
print'提交成功'
end
end