I need to insert bulk data into a table for testing purpose via MySQL script file data.sql
. But I want avoid dumping bulk insert statements into the file. So thought of using a loop
, but without using procedure / function. Somewhat similar to this , here OP wants to achieve this in a Editor and I am looking achieve it using script file.
So i tried to import a script file containing below code, but ended up in error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHILE (i <= 100) DO INSERT INTO
use test_db;
BEGIN
DECLARE int_val INT DEFAULT 0;
test_loop : LOOP
IF (int_val = 10) THEN
LEAVE test_loop;
END IF;
INSERT INTO `test_db`.`ztest_states`
(`city`,`state`,`zip`) VALUES ( 'XXX', 'YYY', '11111');
SET int_val = int_val +1;
SELECT int_val;
END LOOP;
END$$
Please suggest a ways to achieve what I am looking for or better solution. Thanks for your time.