[英]How to create an event to drop the table and the other event if no records exists
I am creating a bus table with an event to maintain th data. 我正在创建一个带有事件的总线表,以维护数据。 Is it possible to drop the table and the
autoDelete
event by DropBusEvent
event if no records exist in the bus table? 如果总线表中没有记录,是否可以通过
DropBusEvent
事件删除表和autoDelete
事件?
stt.execute("CREATE TABLE IF NOT EXISTS bus"
+ "(id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,"
+ "mac VARCHAR(30) NOT NULL UNIQUE,"
+ "route int(11) NOT NULL,"
+ "latitude FLOAT(10,6) NOT NULL,"
+ "longitude FLOAT(10,6) NOT NULL,"
+ "created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
stt.execute("CREATE EVENT IF NOT EXISTS AutoDelete "
+ "ON SCHEDULE EVERY 3 MINUTE "
+ "DO "
+ "DELETE FROM bus WHERE created_at < (NOW() - INTERVAL 3 MINUTE)");
// I tried this statement here but it does not work.
stt.execute("CREATE EVENT IF NOT EXITS DropBusTable "
+ "Do "
+ "DROP TABLES IF EXISTS bus");
I am getting You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EXITS DropBusTableDROP TABLES IF EXISTS bus' at line 1
我收到
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EXITS DropBusTableDROP TABLES IF EXISTS bus' at line 1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EXITS DropBusTableDROP TABLES IF EXISTS bus' at line 1
You have a mistake in your syntax: 您的语法有误:
EXITS
instead of EXISTS
in the line EXITS
而不是EXISTS
stt.execute("CREATE EVENT IF NOT EXITS DropBusTable "
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.