MySQl触发器出错,是否有更好的写作方式?

时间:2011-06-20 15:11:22

标签: mysql sql triggers

您好我在使用下面的触发器时出现以下错误:

inser into shift
-> values<15,3, '08:00:00','14:00:00'>;

ERROR 1048 <23000>: Column 'CashierCode' can not be null

为什么?另外,有没有更好的写作如下?

DELIMITER @
create trigger shist_start
before insert on shift
for each row
begin
if(new.CashierCode not in(
select w.EmployeeCode from WorksOn as w
join shop as s on w.ShopCode = s.ShopCode
join CashMachine as c on s.ShopCode = c.ShopCode
where c.CashMachineID=new.CashMachineID ))
then set new.CashierCode = NULL;
end if;
end;

1 个答案:

答案 0 :(得分:2)

似乎Column'CashierCode'被定义为NOT NULL。您确定此列的非空值吗?

看起来您的触发器正在尝试向此列插入NULL值。更改表定义或在触发器中提供有效值。