Condition Handling Do not use MySQL error code 0 because that indicates success rather than an error condition. For a list of MySQL error codes, see Server Error Message Reference. Do not use SQLSTATE values that begin with  ’00’  because those indicate success rather than an error condition. For a list of SQLSTATE values, see Server Error Message Reference. Condition names referred to in  SIGNAL  or use  RESIGNAL  statements must be associated with SQLSTATE values, not MySQL error codes. Using names for conditions can help make stored program code clearer. For example, this handler applies to attempts to drop a nonexistent table, but that is apparent only if you know that 1051 is the MySQL error code for “unknown table” : By declaring a name for the condition, the purpose of the handler is more readily seen: Here is a named condition for the same condition, but based on the corresponding SQLSTATE value rather than the MySQL error code: The  DECLARE ... HANDLER  statement specifies a handler that deals with one or more conditions. If one of these conditions occurs, the specified  statement  executes.  statement  can be a simple statement such as  SET  var_name  =  value , or a compound statement written using  BEGIN  and  END (see Section 13.6.1, “BEGIN ... END Compound Statement” ). 2807 DECLARE  handler_action  HANDLER FOR  condition_value  [,  condition_value ] ... statement handler_action : { CONTINUE | EXIT | UNDO } condition_value : { mysql_error_code | SQLSTATE [VALUE]  sqlstate_value |  condition_name | SQLWARNING | NOT FOUND | SQLEXCEPTION } 13.6.7.2 DECLARE ... HANDLER Statement DECLARE no_such_table CONDITION FOR SQLSTATE ’42S02’; DECLARE CONTINUE HANDLER FOR no_such_table BEGIN -- body of handler END; DECLARE no_such_table CONDITION FOR 1051; DECLARE CONTINUE HANDLER FOR no_such_table BEGIN -- body of handler END; DECLARE CONTINUE HANDLER FOR 1051 BEGIN -- body of handler END; •SQLSTATE [VALUE]  sqlstate_value : A 5-character string literal indicating an SQLSTATE value.