简体   繁体   English

触发器语法中的MySQL错误

[英]MySQL error in trigger syntax

I'm trying to create a trigger to allow only one line per table. 我正在尝试创建一个触发器,以便每个表只允许一行。 This database will be used by more than one software so I would like this automation to be done by the database. 该数据库将由多个软件使用,因此我希望该数据库可以实现自动化。

Before the insert, the database should clean the previous register, plus the foreign tables. 在插入之前,数据库应清除先前的寄存器以及外部表。

At the moment I'm trying to clean the current table, but I'm having syntax errors 目前,我正在尝试清除当前表,但语法有误

在此处输入图片说明

EDIT: 编辑:

Adding a semicolon on DELETE FROM sensor; DELETE FROM sensor;上添加分号DELETE FROM sensor; 在此处输入图片说明

Try removing the begin/end: 尝试删除开始/结束:

CREATE TRIGGER before_insert_sensor BEFORE INSERT ON `sensor`
FOR EACH ROW
DELETE FROM sensor;

You might encounter issues trying to delete during the insert, though. 不过,您可能会在插入过程中遇到尝试删除的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM