Sybase中默认每个DML语句是一个事务,因此,正确地处理事务和错误就很重要了。
EXEC sp_procxmode 'spname', 'unchained' 让存储过程不在事务链模式中。
create procedure procTransationTest(@param1 int, @param2 char(20))asdeclare @error intdeclare @rowcount intbegin transaction insert table1 (col1, col2) values (@param1, @param2) select @error = @@error, @rowcount = @@rowcount if (@error != 0) begin Rollback transaction raiserror 99999 "error inserting to table1" return 2 --2代表错误 end if (@rowcount !> 0) begin Rollback transaction raiserror 99999 "No row affected" return 1 --1代表警告 endcommit transaction