Created
November 9, 2018 04:21
-
-
Save endrik-exe/679c46ac1fcd7831c70856a0e4629c0c to your computer and use it in GitHub Desktop.
Duplicate Database from template, useful for restore point
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
SELECT @tbl_template := 'vcerp_template', @tbl_target := 'vcerp'; | |
SELECT 'SET FOREIGN_KEY_CHECKS=0;' | |
UNION | |
SELECT Concat('DROP TABLE IF EXISTS ', @tbl_target, '.', TABLE_NAME, ';') | |
FROM INFORMATION_SCHEMA.TABLES | |
WHERE table_schema = @tbl_template | |
UNION | |
SELECT Concat('CREATE TABLE ', @tbl_target, '.', TABLE_NAME, ' LIKE ', @tbl_template, '.', TABLE_NAME, ';') | |
FROM INFORMATION_SCHEMA.TABLES | |
WHERE table_schema = @tbl_template | |
UNION | |
SELECT Concat('INSERT INTO ', @tbl_target, '.', TABLE_NAME, ' SELECT * FROM ', @tbl_template, '.', TABLE_NAME, ';') | |
FROM INFORMATION_SCHEMA.TABLES | |
WHERE table_schema = @tbl_template | |
UNION | |
SELECT 'SET FOREIGN_KEY_CHECKS=1;'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment