MySQL批量插入數據:web
假設如今已經存在表 websign_gold_ticket(id, ticket, ticketType, used)測試
1. 建立存儲過程spa
delimiter $$ CREATE PROCEDURE test_insertData (IN n INT) BEGIN DECLARE i INT DEFAULT 1; WHILE (i <= n) DO INSERT INTO websign_gold_ticket(ticket, ticketType, used) VALUES (i, 3002, 1); SET i = i + 1; END WHILE; END $$ delimiter ;
2. 調用存儲過程, 插入數據code
CALL test_insertData (100) ;
SQLServer批量插入數據(未測試):blog
declare @n int set @i=1 while @i <= 100 begin insert into websign_gold_ticket(ticket, ticketType, used) values(i, 3002, 1); set i = i + 1; end while;