mysql中循环插入数据

2年前 (2022) 程序员胖胖胖虎阿
187 0 0

循环插入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();

 

版权声明:程序员胖胖胖虎阿 发表于 2022年9月7日 下午1:24。
转载请注明:mysql中循环插入数据 | 胖虎的工具箱-编程导航

相关文章

暂无评论

暂无评论...