表结构:
创建函数,用于生成n位的随机字符串:
CREATE DEFINER=’root’@’localhost’ FUNCTION ‘randomString’(‘n’ int) RETURNS varchar(255) CHARSET utf8mb4
BEGIN
DECLARE char_str varchar(100) DEFAULT ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789’;
DECLARE return_str varchar(255) DEFAULT ”;
DECLARE i INT DEFAULT 0;
WHILE i < n DO
SET return_str = concat(return_str, substring(char_str, FLOOR(1 + RAND()*62), 1));
SET i = i+1;
END WHILE;
RETURN return_str;
END- 创建存储过程,用于创建数据
CREATE DEFINER=’root’@’localhost’ PROCEDURE ‘add_vote_record_memory’(IN ‘n’ INT)
BEGIN
DECLARE i INT DEFAULT 0;
DECLARE category INT DEFAULT 0;
DECLARE status INT DEFAULT 0;
WHILE i < n DO
SET category = FLOOR(RAND() * 10);
SET status = FLOOR(RAND()*5);
INSERT INTO ‘video’ VALUES (NULL, randomString(5),category,randomString(3),UUID(),status);
SET i = i + 1;
END WHILE;
END
- 创建存储过程,用于创建数据