Created
November 20, 2020 06:32
-
-
Save SGCreations/6c8703a72c52afb5f2721c73237122eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP PROCEDURE IF EXISTS `drop_all_tables`; | |
DELIMITER $$ | |
CREATE PROCEDURE `drop_all_tables` () | |
BEGIN | |
DECLARE _done int DEFAULT FALSE; | |
DECLARE _tableName varchar(255); | |
DECLARE _cursor CURSOR FOR | |
SELECT | |
table_name | |
FROM information_schema.TABLES | |
WHERE table_schema = SCHEMA(); | |
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = TRUE; | |
SET foreign_key_checks = 0; | |
OPEN _cursor; | |
REPEAT FETCH _cursor INTO _tableName; | |
IF NOT _done THEN | |
SET @stmt_sql = CONCAT('DROP TABLE ', _tableName); | |
PREPARE stmt1 FROM @stmt_sql; | |
EXECUTE stmt1; | |
DEALLOCATE PREPARE stmt1; | |
END IF; | |
UNTIL _done END REPEAT; | |
CLOSE _cursor; | |
SET foreign_key_checks = 1; | |
END$$ | |
DELIMITER ; | |
CALL drop_all_tables(); | |
DROP PROCEDURE IF EXISTS `drop_all_tables`; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment