まずテーブルを作ります。
mysql> create database user;
Query OK, 1 row affected (0.09 sec)
mysql> use user;
Database changed
mysql> create table `user`(
-> `id` int(11) not null auto_increment,
-> `name` varchar(255) not null,
-> `email` varchar(255) not null,
-> `password` varchar(255) not null,
-> `created` datetime not null,
-> `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-> `deleted` datetime DEFAULT null,
-> PRIMARY KEY(`id`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8
-> ;
Query OK, 0 rows affected (0.48 sec)
# ストアドプロシージャ
DELIMITER //
CREATE PROCEDURE testInsert(IN max INT)
BEGIN
DECLARE cnt INT Default 1;
simple_loop: LOOP
INSERT INTO user(name, email, password, created) VALUES (CONCAT('user', cnt), concat('test', cnt, '@test.com'), concat('test_password', cnt), NOW());
SET cnt = cnt+1;
If cnt=max THEN
LEAVE simple_loop;
END IF;
END LOOP simple_loop;
END //
## インサート
CALL testInsert(10000000);
## ストアドプロシージャーの削除
DROP PROCEDURE testInsert;
ストアドプロシージャーって何?