sql批量插入数据
MySQL批量插入数据:
假设现在已经存在表 websign_gold_ticket(id, ticket, ticketType, used)
1. 创建存储过程
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. 调用存储过程, 插入数据
CALL test_insertData (100) ;
SQLServer批量插入数据(未测试):
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;