选课系统,当同意学号选课数量超过则回滚事务,符合条件则正常插入数据
--开始一个事务处理Begin Tran T1 --执行插入操作insert into Courselist values('20100021','01');insert into Courselist values('20100021','02');insert into Courselist values('20100021','03');insert into Courselist values('20100021','04');insert into Courselist values('20100021','05');--判断同一学号的选课数量是否符合IF(select COUNT(StudentID) as cnt from Courselist where StudentID='20100021')>4BEGIN--不符合,回滚事务 rollback Tran T1ENDELSEBEGIN--符合,提交事务 commit Tran T1END
新闻热点
疑难解答