MySQL stored procedure inserts a batch of data or thousands of data MySQL loop statements at a time

Source: Internet
Author: User

Mysql using a stored procedure, you insert a batch of data, you can insert thousands of data, as long as you use the loop statement, it is OK.

mysql ( 5.0 above) in sqlyog Span style= "line-height:33px;font-family: Song Body; font-size:19px" (Version is 8.32 " How to establish a stored procedure:

1,           open sqlyog tools.

2,&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; build table < Span style= "Font-family:times New Roman" >procedurehuihui

CREATE TABLE ' Procedurehuihui ' (

' ID ' BIGINT (a) not NULL auto_increment,

' Code ' VARCHAR DEFAULT NULL,

' Name ' VARCHAR (DEFAULT NULL),

' Dates ' DATE DEFAULT NULL,

PRIMARY KEY (' id ')

) Engine=innodb auto_increment=45 DEFAULT Charset=utf8

3, in theSQLyogin the tool " other  " Stored Procedures  " create a stored procedure

then write the code for the stored procedure inside, where the stored procedure name is CCEE,

galanzkt is the database name, as follows:

DELIMITER $$

CREATE

/*[definer = {User | Current_User}]*/

PROCEDURE ' galanzkt '. ' CCee ' ()

/*language SQL

| [NOT] Deterministic

| {CONTAINS SQL | NO SQL | READS SQL DATA | Modifies SQL DATA}

| SQL SECURITY {definer | INVOKER}

| COMMENT ' String ' */

BEGIN

DECLARE i INT DEFAULT 0;

While I <

INSERT into Procedurehuihui (code,name,dates)

VALUES (' 001 ', ' Xiao Wang ', ' 2011-07-15 ');

SET i = i + 1;

END while;

end$$

DELIMITER;

--------------------------------------------------------------------------------------

The above blue fonts are written on the system by default, we just need to add the things we want to do, such as the Red Font section.

4,&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; again in the normal < Span style= "Font-family:times New Roman" >query inside call stored procedure, for example:

      -- call a stored procedure   

Call CCEE ();

Insert the data you want to insert successfully.


MySQL stored procedure inserts a batch of data or thousands of data MySQL loop statements at a time

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.