当然可以。
你只开始了一个事务,确没有对其做进一步的提交或者回滚。
begin tran tran1
exec cp_graduateBakTBL_Stud_Step_Exam @acadYearName
if @@error<>0
ROLLBACK TRANSACTION tran1
else
commit tansaction tran1
你只开始了一个事务,确没有对其做进一步的提交或者回滚。
begin tran tran1
exec cp_graduateBakTBL_Stud_Step_Exam @acadYearName
if @@error<>0
ROLLBACK TRANSACTION tran1
else
commit tansaction tran1
as
begin tran tran1
exec cp_graduateBakTBL_Stud_Step_Exam @acadYearName
COMMIT TRANSACTION tran1
比如说备份操作,从一个库中的表导到另一个另一个库中的表,有很多表要这样操作。
我想把Commit tran或RollBack Tran等操作放到别的地方,
比如当用户点击备份时执行cp_BakGraduateStudData(此时没有提交),用户可以点击确定(此时提交--运行其它存储过程去Commit tran tran1),或者点击取消(返回,运行其它存储过程去rollBack tran1)
这样可以吗?
然后在cp_graduateBakTBL_Stud_Step_Exam 过程里加事务,当@cancelorexec 为0 时执行,为1 时取消在调用的时候直接这样就行了
set @@cancelorexec = 0 --or 1
exec cp_graduateBakTBL_Stud_Step_Exam @acadYearName,@cancelorexec
然后在cp_graduateBakTBL_Stud_Step_Exam 过程里加事务,当@cancelorexec 为0 时执行,为1 时取消在调用的时候直接这样就行了
set @cancelorexec = 0 --or 1
exec cp_graduateBakTBL_Stud_Step_Exam @acadYearName,@cancelorexec
在退出存储过程时,sql server会再次检查 @@trancount的值
如果该值与前面保存的值不一致,就会有这个警告信息(警告而不是错误),由于业务逻辑的问题,你如果在存储过程中提交或者回滚了事务, 可能导致这个值不一致,所以这是正常的.
alter procedure cp_BakGraduateStudData(@acadYearName int)
asbegin tran tran_BakTBL_ACAD_INFO
exec cp_graduateBakTBL_ACAD_INFObegin tran tran_BakTBL_MAJOR_INFO
exec cp_graduateBakTBL_MAJOR_INFObegin tran tran_BakTBL_STUD_INFO
exec cp_graduateBakTBL_STUD_INFObegin tran tran_BakTBL_STUD_ACHI
exec cp_graduateBakTBL_STUD_ACHIbegin tran tran_BakTBL_STUD_CERT
exec cp_graduateBakTBL_STUD_CERT雏老大你说提示无所谓,可是这样做下面的语句都执行不了。
我想在其它存储过程Commit Tran tran_... 行吗?
还有我在cp_graduateBakTBL_ACAD_INFO这些存储过程中均没有用事务,这样是否合理?