实验中经常会遇到需要多条数据的情况就想到了用SQL语句循环生成数据 DROP PROCEDURE if EXISTS test_insert; DELIMITER ;; CREATE PROCEDURE test_insert() BEGIN DECLARE y BIGINT DEFAULT 1; WHILE y<100000 DO INSERT INTO `sshshop`.`product` (`pname`, `market_price`, `shop_price`, `image`, `
实现目标:一年12个月,每个月插入一条数据,score为1-5的随机数 循环语句: WHILE -- DO -- END WHILE DELIMITER ; CREATE PROCEDURE test_insert() BEGIN DECLARE y TINYINT DEFAULT 1; WHILE y<13 DO INSERT INTO app_sign(`user_id`, `score`, `createdate`) VALUES ('1', FLOOR( 1 + RAND() * 5),
在mysql添加测试数据,想和mssql一样用循环实现,发现不管怎么样都执行失败 经查询发现mysql不支持匿名块,只能先创建出一个存储过程,执行,然后删除 CREATE PROCEDURE test () BEGIN SET @i = ; SET @i = @i + ; WHILE @i < DO SET @i = @i + ; END WHILE; SELECT @i; END
use md5db; DROP PROCEDURE if exists myFunction; delimiter $$ CREATE PROCEDURE myFunction() BEGIN DECLARE i INT DEFAULT 0; WHILE (i<1000001) DO INSERT INTO `md5`(`MD5_TXT`, `MD5_HASH`) VALUES (i,md5(i)); SET i=i+1; END WHILE; END$$ delimiter ; call my
DELIMITER ;; CREATE PROCEDURE test_insert () BEGIN DECLARE i INT DEFAULT 1; WHILE i<100 DO insert into goods(good_name,good_price,de) values ('gui',i,'hao'); SET i=i+1; END WHILE ; commit; END;; CALL test_insert();
双重循环插入 DELIMITER ;; CREATE PROCEDURE test_insert() BEGIN DECLARE a INT DEFAULT 1; DECLARE b TINYINT DEFAULT 1; WHILE (a <= 100) DO -- repeat SET a = a + 1; -- select a; WHILE (b <=20) DO insert into school_sp_mj(school_id,mojor_id,status) values(a,b