Home > Database > Mysql Tutorial > MySql code example for inserting data in a loop

MySql code example for inserting data in a loop

不言
Release: 2019-03-22 10:57:31
forward
3238 people have browsed it

The content of this article is about the code example of MySql loop insertion of data. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

MySql uses stored procedures to insert data

#创建存储过程
CREATE PROCEDURE test_insert () 
    #开始
    BEGIN
        #定义变量 
        DECLARE i INT DEFAULT 1;
            #条件判断
            WHILE i<1000000 
            #执行
            DO 
                #SQL
                INSERT SQL ;
                #变量增加
                SET i=i+1;
            #结束循环 
            END WHILE ;
        #提交 
        commit; 
    #结束
    END;
#执行
CALL test_insert();    
#删除存储过程
drop procedure test_insert ;
#查看存储过程
SHOW PROCEDURE STATUS ;
#查看创建存储过程的语句
SHOW CREATE PROCEDURE test_insert8 ;
Copy after login

This article has ended here. For more other exciting content, you can pay attention to the MySQL tutorial video on the PHP Chinese website Column!

The above is the detailed content of MySql code example for inserting data in a loop. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template