0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2018-07-24

サンプル

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

テーブル用意

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);

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?