Home > database >  Mysql newbie on the road
Mysql newbie on the road

Time:10-12

Intellect mysql didn't take long, but every time the assignment than bother everybody to help to take a look at the second question! What is to use stored procedures or transaction or together?

CodePudding user response:

 
Delimiter//
CREATE PROCEDURE test. Delete11 (IN xuehao VARCHAR (255))
The BEGIN
DECLARE the EXCEPTION INT the DEFAULT 0;
DECLARE the EXIT HANDLER FOR SQLEXCEPTION SET EXCEPTION=1;
START the TRANSACTION;
The DELETE FROM stu WHERE StuID=xuehao;
The DELETE FROM scores the WHERE StuID=xuehao;
IF the EXCEPTION=1 THEN
The ROLLBACK.
The ELSE
COMMIT;
END IF;

END
//

  • Related