有約束balance不能小於50
--通過事務執行轉賬
--打開一個事務
begin transaction
declare @money money=10,@sum int =0
update bank set balance=balance-@money where account_id='00001'
set @sum=@sum+@@error
update bank set balance=balance+@money where account_id='00002'
set @sum=@sum+@@error
--只要有任何一個語句出錯那麼最後的sum就不是0
if @sum<>0
begin
--表示程序執行出錯,回滾
rollback
end
else
begin
--表示沒有出錯,則提交該事務
commit
end