Leave a Comment
MySQL: generate and insert a range of dummy rows
There are a lot of ways to do this, but the one below is the most straightforward to me.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
delimiter | CREATE PROCEDURE generate_seq(n BIGINT UNSIGNED) BEGIN DECLARE i BIGINT UNSIGNED DEFAULT 0; WHILE i < n DO INSERT INTO orders ( code, customer_code, added_at_utc ) VALUES( CONCAT('ordr-', i), CONCAT('custom-', i), CURRENT_TIME() ); SET i = i + 1; END WHILE; END| delimiter ; CALL generate_seq(1000000); |
Much more ways to achieve the same result can be found here — https://www.percona.com/blog/2020/07/27/generating-numeric-sequences-in-mysql/
Similar Posts
LEAVE A COMMENT
Для отправки комментария вам необходимо авторизоваться.