• Mysql使用存储过程插入十万条数据


    一、建表语句

    SET NAMES utf8mb4;
    SET FOREIGN_KEY_CHECKS = 0;
    
    -- ----------------------------
    -- Table structure for user_info
    -- ----------------------------
    DROP TABLE IF EXISTS `user_info`;
    CREATE TABLE `user_info`  (
      `id` int(0) NOT NULL AUTO_INCREMENT,
      `name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
      `age` int(0) NULL DEFAULT NULL,
      `gender` varchar(5) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
      `address` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
      `tel` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
      PRIMARY KEY (`id`) USING BTREE
    ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
    
    SET FOREIGN_KEY_CHECKS = 1;
    
    

    二、存储过程

    -- 如果存在同名存储过程则删除.
    DROP PROCEDURE IF EXISTS my_insert;
    
    -- 创建存储过程
    CREATE PROCEDURE my_insert()
    BEGIN
       DECLARE n int DEFAULT 0;
            loopname:LOOP
                INSERT INTO user_info(name,age,gender,address,tel)VALUES('abc',23,'男','中国',18712341234);
                SET n=n+1;
            IF n=100000 THEN
                LEAVE loopname;
            END IF;
            END LOOP loopname;
    END;
    
    -- 执行存储过程
    CALL my_insert();
    
  • 相关阅读:
    DB设计原则
    英文地址[转]
    ICollection
    雅虎优化14条
    vue过滤器
    php中echo(),print(),print_r()之间的区别
    jQ中对attr()方法的理解
    浅析call和apply的不同
    浅析call和apply
    PHP是弱类型语言,自动转换,强制转换
  • 原文地址:https://www.cnblogs.com/yang37/p/14600808.html
Copyright © 2020-2023  润新知