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
我收到你的SQL语法错误;检查与MySQL服务器版本对应的手册,以便在第1行的'EXITS DropBusTableDROP TABLES IF EXISTS bus'附近使用正确的语法
1 个解决方案
#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 "
#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 "