更新时间:2022-12-10 18:26:01
您可以使用插入后触发器
You can use an "after insert trigger"
之后在注册表中插入
并在出现以下情况时使用 New.IdRegistro作为外键
And take the "New.IdRegistro" to use as foreign key when populating the alarmes table.
//编辑:
使用您的代码:
// using your code:
AFTER INSERT ON registos
FOR EACH ROW
begin
Set @tempmax=0;
Set @tempmin=0;
Set @hummax=0;
...
INSERT INTO alarmes(idAlarme,descricao_alarme,idRegistro) VALUES (@maxidAlarme,"lower temperature",New.IdRegistro);
INSERT INTO sensores_tem_alarmes(idSensor,idAlarme,dataAlarme) VALUES (NEW.idSensor,@maxidAlarme,NOW());
...
我在这里IdRegistro是注册表表的主键(将由您的应用程序自动生成,或通过自动递增生成)。
I assume here that IdRegistro is a primary key (that will be autogenarated by your application or via autoincrement) of the registro table.
Register->如果值是高/低阈值->触发警报->插入sensores_tem_alarmes
Register->if value higher/lower threshold -> trigger alarm -> insert sensores_tem_alarmes