2016-09-06 13 views
0

私はあなたが前に区切り文字を変更する必要がこのSQLトリガー信号に何が問題なのですか?

create trigger employee_no_rate_self before insert on Feedback 
for each row 
    begin 
    if NEW.Submitter_Employee_id = NEW.Recipient_Employee_id THEN 
    signal sqlstate '45000' 
    set message_text = 'Can\'t rate oneself'; 
    end if; 
end; 
+1

カント等しいRecipient_IdをSubmitter_Employee_ID、与えられた行で言うしようとしています: '区切り文字|' –

答えて

1
create table Feedback 
( id int auto_increment primary key, 
    message varchar(20) not null, -- brevity is King 
    Submitter_Employee_id int not null, 
    Recipient_Employee_id int not null 
); 


drop trigger if exists employee_no_rate_self; 
delimiter $$ 
create trigger employee_no_rate_self before insert on Feedback 
for each row 
    begin 
    if NEW.Submitter_Employee_id = NEW.Recipient_Employee_id THEN 
    signal sqlstate '45000' 
    set message_text = 'Can\'t rate oneself'; 
    end if; 
end; $$ 
delimiter ; 

insert Feedback (message,Submitter_Employee_id,Recipient_Employee_id) values 
('hello',1,2); 
-- success 

insert Feedback (message,Submitter_Employee_id,Recipient_Employee_id) values 
('bye',2,2); 
-- error: Can't rate oneself 
関連する問題