MySQL 如何批量造数据
CREATE TABLE
IF NOT EXISTS tmp_table (
`id` VARCHAR (64) NOT NULL,
`second_id` VARCHAR (64) NOT NULL,
`total_amount` DOUBLE (18, 2) DEFAULT NULL,
`total_day` INT (11) DEFAULT NULL,
`create_time` datetime NOT NULL,
`edit_time` datetime DEFAULT NULL,
`editor` VARCHAR (50) DEFAULT NULL,
`status` INT (11) NOT NULL DEFAULT '0'
) DEFAULT CHARSET = utf8mb4;
DROP PROCEDURE IF EXISTS proc_initData;--如果存在此存储过程则删掉
DELIMITER $
CREATE PROCEDURE proc_initData()
BEGIN
DECLARE i INT DEFAULT 1;
WHILE i<=10000 DO
INSERT INTO data(user_id) VALUES(i);
SET i = i+1;
END WHILE;
END $
CALL proc_initData();
DELIMITER $
CREATE PROCEDURE proc_initData()
BEGIN
DECLARE i INT DEFAULT 1;
DECLARE id VARCHAR (64) DEFAULT 1;
DECLARE second_id VARCHAR (64) DEFAULT 1;
WHILE i<=10000 DO
INSERT INTO aishu.tmp_table (
`id`,
`second_id`,
`total_amount`,
`total_day`,
`create_time`,
`edit_time`,
`editor`,
`status`
)
VALUES
(
id,
second_id,
ceiling(5 - 1 + rand() *(10 -(5 - 1))),
FLOOR(5 + RAND() *(7 + 1 - 5)),
SYSDATE(),
SYSDATE(),
'mysql存储过程',
'0'
) ;
SET i = i+1;
SET id = id + 1 ;
SET second_id = second_id + 1 ;
END WHILE;
END $
CALL proc_initData();
THE END