mysql 创建一个表,并创建存储过程,插入测试数据

CREATE TABLE `test_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  `address` varchar(45) DEFAULT NULL,
  `score` int(3) DEFAULT NULL,
  `class` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

DELIMITER ;; 
CREATE PROCEDURE insert_test_data()
BEGIN  
DECLARE i INT DEFAULT 1;
WHILE i <= 1000 DO
INSERT INTO test_table(name, age, address, score, class) VALUES (CONCAT('name_', i),   FLOOR(100*RAND()+10), CONCAT('address_', i), FLOOR(100*RAND()+10), CONCAT('class_', FLOOR(10*RAND()+1)));  
SET i = i + 1;  
END WHILE;
END;;

DELIMITER ;
CALL insert_test_data();
posted @ 2023-04-25 11:19  darling331  阅读(94)  评论(0编辑  收藏  举报