触发器仍在工作,甚至输入了错误的输入
我的问题是,即使我放了错误的字母,除了“ F”或“ M”外,触发器仍然更新。另外,即使我将“ F”或“ M”字母放在小写中,触发器仍然可以正常工作。如果输入不正确,我要如何使触发器不起作用?例如将错误的字母放在小写字母中。
这是我的代码:
CREATE TRIGGER trgAllowance -- trigger name
BEFORE UPDATE
ON tab_employee FOR EACH ROW
BEGIN
IF new.EmpGender = 'F' THEN
SET new.SpecialAllowance = (new.Salary*0.2); /* Count the amount of Salary times by specific amount */
ELSEIF new.EmpGender = 'M' THEN
SET new.SpecialAllowance = (new.Salary*0.05);
END IF;
END
My problem is, even i put the wrong alphabet other than 'F' or 'M', the trigger still updated. Also, even i put the 'F' or 'M' alphabet in lowercase, the trigger still function. how i want to make the trigger not function if the input is not correct? such as putting the wrong alphabet with lowercase.
here is my code :
CREATE TRIGGER trgAllowance -- trigger name
BEFORE UPDATE
ON tab_employee FOR EACH ROW
BEGIN
IF new.EmpGender = 'F' THEN
SET new.SpecialAllowance = (new.Salary*0.2); /* Count the amount of Salary times by specific amount */
ELSEIF new.EmpGender = 'M' THEN
SET new.SpecialAllowance = (new.Salary*0.05);
END IF;
END
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论