mysql--loop insert data into table

Source: Internet
Author: User

Memo: 1. The search found that MySQL does not support the direct write SQL statement to implement the loop insertion function. To implement this feature, you can either manipulate MySQL in another language, or use a stored procedure to implement it (store PROCEDURE--SP).  2. The following is an SP implementation pass, write down to be afraid to forget. --Table structure definition Tdefuser, there is an auto-increment PK: /tbody>

T able create table 
------------------------------------------------------------------
tdefuser create table  ' Tdefuser '   ( 
              ' UserId '  int (one)  not null auto_increment, 
              ' Address '  varchar ( default)  NULL,&NBSP
             ' phone '   varchar ( default null, );
             primary key  (' userId ')  
          )  ENGINE=MYISAM AUTO_INCREMENT=10001 DEFAULT CHARSET=LATIN1&NBSP

--Stored procedure implementation, AutoInsert:

DELIMITER $$

DROP PROCEDURE IF EXISTS `hibernate`.`autoInsert`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `autoInsert`()
BEGIN
    DECLARE i int default 1;
    WHILE(i < 10000) DO
        insert into tdefuser(address, phone) value (‘sz‘, ‘123‘);
        SET i = i+1;
    END WHILE;
    END$$

DELIMITER ;

--Complete, call AutoInsert (); invoke the SP.

mysql--loop insert data into table

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.