我正在创建一个包含事件的总线表来维护数据。如果总线表中没有记录,是否可以通过autoDelete
事件删除表和DropBusEvent
事件?
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");
我正在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
答案 0 :(得分:0)
你的语法有误:
EXITS
代替EXISTS
在行
stt.execute("CREATE EVENT IF NOT EXITS DropBusTable "