MySQL快速插入大批量数据存储过程


MySQL快速插入大批量数据存储过程

  1. -- ---------------------------- 
  2. -- Table structure for `test` 
  3. -- ---------------------------- 
  4. DROP TABLE IF EXISTS `test`; 
  5. CREATE TABLE `test` ( 
  6.   `id` int(11) NOT NULL AUTO_INCREMENT, 
  7.   `ordernum` varchar(255) NOT NULL, 
  8.   PRIMARY KEY (`id`) 
  9. ENGINE=InnoDB AUTO_INCREMENT=500001 DEFAULT CHARSET=utf8
  10.  
  11.  
  12. begin 
  13. set @beginnum=1
  14. set @endnum=500001
  15.  
  16. start transaction; 
  17. while @beginnum < @endnum do 
  18.  
  19. set @v_beginnum=LPAD(@beginnum,7,0); 
  20. set @order=concat(20121105,@v_beginnum); 
  21.  
  22. INSERT INTO test ( ordernum ) 
  23. VALUES 
  24.     ( 
  25.         @order 
  26.     ); 
  27.  
  28.     set @beginnum=@beginnum+1; 
  29.  end while; 
  30.  commit; 
  31.  end 

相关内容