事务处理

SET NOCOUNT ON;
BEGIN TRANSACTION TT
if(@count>0)
begin
select 2 from P01
end  
else
begin
select 3 From P01
end;
    SET NOCOUNT OFF;
COMMIT TRANSACTION TT;
RETURN 1


--回滚事务
ERRMSG:
BEGIN
SET NOCOUNT OFF;
ROLLBACK TRANSACTION TT
SELECT -1 AS RESULT, 'Database error, please ask database manager to check!' AS WARNING
RETURN -1   --添加失败并回滚
END 

你可能感兴趣的:(sql)