MySql 批量插入测试数据

2020-02-14  本文已影响0人  麦特桃塔总

创建测试表

CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  `age` int(10) DEFAULT NULL,
  `ctime` datetime DEFAULT NULL COMMENT '创建时间',
  `utime` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COMMENT='用户测试表';

插入方法

DROP PROCEDURE if exists test_insert ;
DELIMITER ;;

CREATE PROCEDURE test_insert ()
BEGIN

DECLARE i INT DEFAULT 1;# can not be 0

-- 插入条数
WHILE i<100
DO
-- 插入语句
INSERT INTO user(id, name, age, ctime, utime) VALUES (i,  CONCAT("姓名",i), 32, now(), null);

SET i=i+1;
END WHILE ;
commit;

END;;

CALL test_insert();
上一篇下一篇

猜你喜欢

热点阅读