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; 

 

相关文章:

  • 2021-12-03
  • 2021-12-16
  • 2021-12-27
  • 2022-02-17
  • 2022-12-23
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
猜你喜欢
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
  • 2022-02-21
相关资源
相似解决方案