什么 sql 查询可以生成 100,000 mysql 行随机数据?

What the sql query can generate 100,000 mysql rows with random data?

我有 12 列的 table,如何通过 sql 查询在行的每一列中插入 100 个随机符号以生成 100 000 行

您必须使用程序来完成此任务:

DELIMITER $$
CREATE PROCEDURE InsertRandomRows(IN NumRows INT)
    BEGIN
        DECLARE i INT;
        SET i = 1;
        START TRANSACTION;
        WHILE i <= NumRows DO
            INSERT INTO table_name (status, tel_mobile, tel_home, age,
                call_time, created_at, fio, address, comment) VALUES (
                ROUND(RAND() * 1000000),
                ROUND(RAND() * 1000000),
                ROUND(RAND() * 1000000),
                ROUND(RAND() * 1000000),
                ROUND(RAND() * 1000000),
                ROUND(RAND() * 1000000),
                LEFT(CONCAT(
                    MD5( CAST( RAND() AS CHAR )),
                    MD5( CAST( RAND() AS CHAR )),
                    MD5( CAST( RAND() AS CHAR )),
                    MD5( CAST( RAND() AS CHAR ))
                ), 100),
                LEFT(CONCAT(
                    MD5( CAST( RAND() AS CHAR )),
                    MD5( CAST( RAND() AS CHAR )),
                    MD5( CAST( RAND() AS CHAR )),
                    MD5( CAST( RAND() AS CHAR ))
                ), 100),
                LEFT(CONCAT(
                    MD5( CAST( RAND() AS CHAR )),
                    MD5( CAST( RAND() AS CHAR )),
                    MD5( CAST( RAND() AS CHAR )),
                    MD5( CAST( RAND() AS CHAR ))
                ), 100)
            );
            SET i = i + 1;
        END WHILE;
        COMMIT;
    END$$
DELIMITER ;


CALL InsertRandomRows(100000);

对于文本字段,我使用 "MD5" 函数创建一个随机的 32 个字符长的字符串,连接其中的 4 个(32 x 4 = 128 个字符)并截断前 100 个字符。

对于整数字段,您可以直接使用 RAND 来生成随机数。

希望对您有所帮助!

编辑:抱歉,我错了,LEFT 函数参数被交换了。