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.
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/
LEAVE A COMMENT
Для отправки комментария вам необходимо авторизоваться.