mysql触发器语法注意事项

mysql触发器语法注意事项

注意点:
1. 在if条件里的必须是变量(@xxx)
2. set分号结尾
3. end if注意分号结尾
4. 条件中执行的sql语句注意分号结尾

例子:
Navicat 创建触发器
mysql触发器语法注意事项_第1张图片
BEGIN
set @dataTime = date(new.dataTime);
set @nowTime = date(now());
set @yearDT = year(new.dataTime);
set @monthDT = month(new.dataTime);
set @yearN = year(now());
set @monthN = month(now());
if @dataTime = @nowTime then
insert into t_senor_data_day values(new.id,new.deviceId,new.senorId,new.tenantId,new.dataValue,new.dataTime,new.receiveTime,new.taskType,new.paramType,new.senorType);
end if;
if @yearDT = @yearN and @monthDT = @monthN then
insert into t_senor_data_month values(new.id,new.deviceId,new.senorId,new.tenantId,new.dataValue,new.dataTime,new.receiveTime,new.taskType,new.paramType,new.senorType);
end if;
end

你可能感兴趣的:(mysql触发器语法注意事项)