0

それでもゼロ値の挿入を許可します..

    CREATE TRIGGER check_my_constraint BEFORE insert ON `personal_details`
         FOR EACH ROW 
         BEGIN
         DECLARE msg varchar(255);
         IF (NEW.studentid<0)
         THEN
            SET msg = concat('Constraint my_constraint violated: studentid must not be zero ', cast(new.studentid as char));
            SIGNAL sqlstate '45000' SET message_text = msg;
         END IF; 
         END ;
4

2 に答える 2

1

条件を変更 -

IF (NEW.studentid<0)=>IF (NEW.studentid <= 0)

于 2013-04-10T09:49:11.217 に答える
1

ゼロ未満のみをチェックします。ゼロ以下であることを確認する必要があります。

IF (NEW.studentid <= 0)
于 2013-04-10T09:49:15.827 に答える