我的sql脚本是这样的:
CREATE
EVENT `deleteEvent`
ON SCHEDULE EVERY 30 MINUTE STARTS '2016-03-23 00:00:00'
ON COMPLETION NOT PRESERVE
ENABLE
DO
DELETE FROM hotel;
ALTER TABLE hotel AUTO_INCREMENT = 1;
我不使用truncate。因为,有这样的错误:
Cannot truncate a table referenced in a foreign key constraint.........
所以,我使用Delete和alter
但是,当使用删除和更改时,它不起作用
解决我问题的任何解决方案?
谢谢
答案 0 :(得分:1)
您可以尝试:如果清除这两个表,则可以使用TRUNCATE。截断后Auto_inc也是1
SET foreign_key_checks = 0;
TRUNCATE FROM hotel;
TRUNCATE FROM ConstraintsTable;
SET foreign_key_checks = 1;
您可以设置更多类似的查询:
DELIMITER //
CREATE EVENT myevent
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
DO
BEGIN
SET foreign_key_checks = 0;
TRUNCATE FROM hotel;
TRUNCATE FROM ConstraintsTable;
SET foreign_key_checks = 1;
END
//
DELIMITER ;