【数据库功能测试】mysql中循环插入数据

循环插入1w条数据

表结构:

mysql> desc time_table;
+-------+-----------+------+-----+-------------------+-----------------------------+
| Field | Type      | Null | Key | Default           | Extra                       |
+-------+-----------+------+-----+-------------------+-----------------------------+
| b1    | date      | YES  |     | NULL              |                             |
| b2    | time      | YES  |     | NULL              |                             |
| b3    | datetime  | YES  |     | NULL              |                             |
| b4    | timestamp | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------+-----------+------+-----+-------------------+-----------------------------+
4 rows in set (0.00 sec)

 插入时间数据:

drop procedure if exists lr_time;

delimiter $$

create procedure lr_time()
begin
    declare n int default 1;
    declare MAX int default 10001;
    while n < MAX do
        insert into time_table values (curdate(), curtime(), now(), localtimestamp());
        set n = n + 1;
        select sleep(1); 
    end while;
end
$$

delimiter ; 

call lr_time();
大道至简
原文地址:https://www.cnblogs.com/liurong07/p/11806584.html