关于数据库事务的基本概念,我还弄不明白。
有这样一个例子,给一个班级添加学员,班级只能有50个人,现在要往里面添加n个学员,查询和添加要在同一个事务里完成。
在单机环境下,可以这么写:
select count(*) from aClass
if count+n<50 then
insert students to aClass
else
throw Exception
end if
但是在多用户环境下,是不是就得用到事务了,是不是照搬下来就可以了呢?
Transaction.begin
select count(*) from aClass
if count+n<50 then
insert students to aClass
else
Transaction.rollback
end if
Transaction.commit
这么简单吗?begin、commit、rollback的位置对不对呢?