MySQL 批量数据循环插入


-- 创建表

CREATE TABLE `test` (
  `school_id` int(11) DEFAULT NULL,
  `mojor_id` tinyint(4) DEFAULT NULL,
  `status` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- 单个循环插入多条数据
DELIMITER ;; 
CREATE PROCEDURE test_insert() 
BEGIN 
DECLARE y TINYINT DEFAULT 1;
WHILE y<20
DO
insert into school_sp_mj(school_id,mojor_id,status) values(1,y,1); 
SET y=y+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 test(school_id,mojor_id,status) values(a,b,1); 
SET b = b + 1; 
-- select b; 
END WHILE; 

SET b = 1; 
-- select a; 
-- until a >= i_PlayerCount 
-- end repeat; 
END WHILE; 
commit; 
END;; 
CALL test_insert();

 

你可能感兴趣的:(Mysql,相关资料)