mysql儲存過程中使用事務

2021-07-09 13:43:31 字數 1552 閱讀 9603

mysql儲存過程中使用事務

1

drop

procedure

ifexists

test_sp1

2create

procedure

test_sp1( )

3begin

4declare t_error integer

default

0;

5declare

continue handler for sqlexception set t_error=

1;

67 start transaction

; 8

insert

into test values(null, '

test sql 001

');

9insert

into test values('

1', '

test sql 002

');

1011

if t_error =

1then

12rollback

; 13

else

14commit

; 15

endif

; 16

17end

返回執行狀態,即是提交了還是回滾了:

1

drop

procedure

ifexists

test_sp1

2create

procedure

test_sp1( )

3begin

4declare t_error integer

default

0;

5declare

continue handler for sqlexception set t_error=

1;

67 start transaction

; 8

insert

into test values(null, '

test sql 001

');

9insert

into test values('

1', '

test sql 002

');

1011

if t_error =

1then

12rollback

; 13

else

14commit

; 15

endif

; 16

select

t_error; //返回標識位的結果集;

17end

儲存過程中使用事務

create procedure updatewanjun username nvarchar 500 userpassword nvarchar 500 returnval int output as set xact abort on begin transaction t update adm...

SQL SERVER儲存過程中使用事務

儲存過程格式 create procedure yourprocedure asbegin set nocount on begin try 開始捕捉異常 bein tran 開始事務 update a set a.names b.names from t1 as a inner join t2 a...

SqlServer儲存過程中使用事務,示例

create proc pro getprotrans goodsid int,number int,stockprice money,supplierid int,empid int,stockunit varchar 50 stockdate datetime,totalmoney money ...