MySQL Forums
Forum List  »  InnoDB

Re: Check constraint not working
Posted by: Devart Team
Date: October 31, 2012 09:00AM

+I will create the trigger
+check the condition
-will post the output

Not 'post the output', you shoul generate the error to cancel insertion.

DELIMITER $$

CREATE TRIGGER trigger1
BEFORE INSERT
ON items
FOR EACH ROW
BEGIN
  IF NEW.ROL >= NEW.QOH THEN
    SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'ROL must be less then QOH';
  END IF;
END$$

DELIMITER ;

In this example I have generated the error with a help of SIGNAL statement. This command is available from MySQL 5.5. On old versions you can call nonexistent stored procedure.

Devart Company,
MySQL management tools
http://www.devart.com/dbforge/mysql/

Options: ReplyQuote


Subject
Views
Written By
Posted
12354
October 27, 2012 05:28AM
2823
October 28, 2012 03:06PM
2224
October 28, 2012 03:10PM
2279
October 31, 2012 03:08AM
1937
October 31, 2012 07:22AM
Re: Check constraint not working
2687
October 31, 2012 09:00AM
2077
November 08, 2012 01:03PM


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.