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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM