MySQL Forums
Forum List  »  Triggers

Re: Trigger Try/Catch
Posted by: Roland Bouman
Date: September 04, 2005 12:36PM

Yes, use a handler for this:

http://dev.mysql.com/doc/mysql/en/declare-handlers.html

create trigger tgr
after insert on mytable
for each row
begin
declare continue handler
for SQLSTATE '23000'
call p_handle_duplicate();
/*
You original trigger code goes here
*/
end;

The call to p_handle_duplicate(); is just a placeholder for your handler. You can put any statement there. For a sequence of statement, use a begin..end block that contains the actual handler code.

For a complete list of existing error conditions, see

http://dev.mysql.com/doc/mysql/en/error-handling.html

Now, SQLSTATE 23000 is a bit arcane, and if you are going to use that again, its better to declare a condition:

create trigger tgr
after insert on mytable
for each row
begin
declare DUPLICATE_ROW condition for SQLSTATE '23000'
declare continue handler
for DUPLICATE_ROW
call p_handle_duplicate();
/*
You original trigger code goes here
*/
end;

More info on condition declarations:

http://dev.mysql.com/doc/mysql/en/declare-conditions.html

Good luck!

Options: ReplyQuote


Subject
Views
Written By
Posted
16175
September 03, 2005 01:43PM
Re: Trigger Try/Catch
8959
September 04, 2005 12:36PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.