ch10-12.zip
大小:3.49KB
价格:25积分
下载量:0
评分:
5.0
上传者:redredddd
更新日期:2024-10-21

ch10-12.zip

资源文件列表(大概)

文件名
大小
ch10-key/实践10-3-1.sql
79B
ch10-key/实践10-3-2.sql
219B
ch10-key/实践10-3-3.sql
243B
ch10-key/实践10-3-4.sql
336B
ch10-key/实践10-3-5.sql
234B
ch10-key/实践10-3-6.sql
298B
ch11-key/实践11-3-1.sql
61B
ch11-key/实践11-3-2.sql
222B
ch11-key/实践11-3-3.sql
111B
ch11-key/实践11-3-4.sql
64B
ch11-key/实践11-3-5.sql
470B
ch12-key/实践11-4.sql
1.4KB

资源内容介绍

ch10-12.zip
use librarygo--创建帐户表bank--if exists(select * from sys.objects where name='bank') drop table bankcreate table bank(customerName char(10), --顾客姓名currentMoney money --当前余额)goalter table bank add constraint CK_currentMoney check(currentMoney>=1)insert into bank(customerName,currentMoney)select '张三',1000 unionselect '李四',1select * from bankgouse librarygo--恢复原来的数据--update bank set currentMoney=currentMoney-1000 where customerName='李'set nocount on --不显示受影响的行数print '查看转帐事务前的余额'select * from bankgobegin transactiondeclare @errorSum int --定义变量,用于累计事务执行过程中的错误update bank set currentMoney=currentMoney-800 where customerName='张三'set @errorSum=@errorSum+@@error --累计是否有错误update bank set currentMoney=currentMoney+800 where customerName='李四'set @errorSum=@errorSum+@@error --累计是否有错误print '查看转帐事务过程中的余额'select * from bankif @errorSum>0 begin print '交易失败,回滚事务.' rollback transaction endelse begin print '交易成功,提交事务,写入硬盘,永久保存!' commit transaction endgoprint '查看转帐后的余额'select * from bankgo

用户评论 (0)

发表评论

captcha