MySQL错误1142 DROP命令被拒绝

时间:2015-03-30 13:05:10

标签: mysql stored-procedures procedures

我无法从程序中删除表格。 这是它给我错误的过程。

CREATE PROCEDURE `procDropAllTables`()
BEGIN
    DECLARE table_name VARCHAR(255);
    DECLARE end_of_tables INT DEFAULT 0;

    DECLARE cur CURSOR FOR
        SELECT t.table_name 
        FROM information_schema.tables t 
        WHERE t.table_schema = DATABASE() AND t.table_type='BASE TABLE';
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET end_of_tables = 1;

    SET FOREIGN_KEY_CHECKS = 0;
    OPEN cur;

    tables_loop: LOOP
        FETCH cur INTO table_name;

        IF end_of_tables = 2 THEN
            LEAVE tables_loop;
        END IF;

        SET @s = CONCAT('DROP TABLE IF EXISTS ' , table_name);
        PREPARE stmt FROM @s;
        EXECUTE stmt;

    END LOOP;

    CLOSE cur;
    SET FOREIGN_KEY_CHECKS = 1;
END

如果我这样做,我可以删除drop table,因此它不是用户权限问题

0 个答案:

没有答案