Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

MySQLで、ランダムな文字列を挿入するだけのプロシージャ

More than 1 year has passed since last update.

サンプル

ランダムな文字列を挿入するだけのプロシージャ

テーブル用意

CREATE TABLE `test` (id INT(11) NOT NULL AUTO_INCREMENT, string VARCHAR(32), created_date TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

プロシージャ作成

DELIMITER //
CREATE PROCEDURE f(n INT)
BEGIN
    DECLARE i int DEFAULT 0;
    WHILE i < n DO
        INSERT INTO `test` (`string`) SELECT MD5(RAND());
        SET i = i + 1;
    END WHILE;
END //
DELIMITER ;

プロシージャ実行

CALL f(1000);

参考
- https://qiita.com/tayasu/items/c5ddfc481d6b7cd8866d

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away