天天看點

mysql 周遊插入資料_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();