DROP SCHEMA IF EXISTS tb0; CREATE SCHEMA tb0; USE tb0; DELIMITER § CREATE PROCEDURE create_tbl() BEGIN DECLARE cnt INTEGER DEFAULT 1; DECLARE cntminusone INTEGER DEFAULT 0; DROP TABLE IF EXISTS t0; CREATE TABLE t0(i INTEGER, j INTEGER, PRIMARY KEY(i))ENGINE=INNODB; WHILE cnt < 1000 DO SET @droptable = CONCAT('DROP TABLE IF EXISTS t', cnt); PREPARE ps1 FROM @droptable; EXECUTE ps1; SET @createtable = CONCAT('CREATE TABLE t', cnt, '(i INTEGER, j INTEGER, PRIMARY KEY(i), FOREIGN KEY(i) REFERENCES t', cntminusone, '(i))Engine=Innodb'); PREPARE ps2 FROM @createtable; EXECUTE ps2; SET cnt = cnt + 1; SET cntminusone = cntminusone + 1; END WHILE; END§ DELIMITER ; CALL create_tbl(); DROP SCHEMA IF EXISTS tb1; CREATE SCHEMA tb1; USE tb1; DELIMITER § CREATE PROCEDURE create_tbl() BEGIN DECLARE cnt INTEGER DEFAULT 1; DECLARE cntminusone INTEGER DEFAULT 0; DROP TABLE IF EXISTS t0; CREATE TABLE t0(i INTEGER, j INTEGER, PRIMARY KEY(i), FOREIGN KEY(j) REFERENCES tb0.t0(i))ENGINE=INNODB; WHILE cnt < 300 DO SET @droptable = CONCAT('DROP TABLE IF EXISTS t', cnt); PREPARE ps1 FROM @droptable; EXECUTE ps1; SET @createtable = CONCAT('CREATE TABLE t', cnt, '(i INTEGER, j INTEGER, PRIMARY KEY(i), FOREIGN KEY(i) REFERENCES t', cntminusone, '(i))Engine=Innodb'); PREPARE ps2 FROM @createtable; EXECUTE ps2; SET cnt = cnt + 1; SET cntminusone = cntminusone + 1; END WHILE; CREATE TABLE t300(i INTEGER, j INTEGER, PRIMARY KEY(i), FOREIGN KEY(j) REFERENCES tb0.t700(i))ENGINE=INNODB; END§ DELIMITER ; CALL create_tbl(); DROP SCHEMA IF EXISTS tb2; CREATE SCHEMA tb2; USE tb2; DELIMITER § CREATE PROCEDURE create_tbl() BEGIN DECLARE cnt INTEGER DEFAULT 1; DECLARE cntminusone INTEGER DEFAULT 0; DROP TABLE IF EXISTS t0; CREATE TABLE t0(i INTEGER, j INTEGER, PRIMARY KEY(i), FOREIGN KEY(j) REFERENCES tb1.t0(i))ENGINE=INNODB; WHILE cnt < 300 DO SET @droptable = CONCAT('DROP TABLE IF EXISTS t', cnt); PREPARE ps1 FROM @droptable; EXECUTE ps1; SET @createtable = CONCAT('CREATE TABLE t', cnt, '(i INTEGER, j INTEGER, PRIMARY KEY(i), FOREIGN KEY(i) REFERENCES t', cntminusone, '(i))Engine=Innodb'); PREPARE ps2 FROM @createtable; EXECUTE ps2; SET cnt = cnt + 1; SET cntminusone = cntminusone + 1; END WHILE; CREATE TABLE t300(i INTEGER, j INTEGER, PRIMARY KEY(i), FOREIGN KEY(j) REFERENCES tb0.t700(i))ENGINE=INNODB; CREATE TABLE t301(i INTEGER, j INTEGER, PRIMARY KEY(i), FOREIGN KEY(j) REFERENCES tb1.t100(i))ENGINE=INNODB; END§ DELIMITER ; CALL create_tbl();