-1
嗨我需要编写一个触发器来检查值是否存在于列中,如果是,则不要插入它并通过错误。 有一列只能有两个值(与bool相同)DEFAULT或NONDEFAULT。插入前触发
此列可以有多个NONDEFAULT值,但列中只有一个DEFAULT值。
如果DEFAULT存在于表中,我们需要通过一个错误并且不应该插入新行。
请帮助
create trigger status_value before insert on TABLE for each row
begin
if new.status=DEFAULT AND select count(status) from TABLE where status=DEFAULT)
then
signal sqlstate = '4500'
set message_text = 'can not update, default value already present'
end if;
end;
谢谢它的工作.. :) – Ashutosh