• <tfoot id='fw8bY'></tfoot><legend id='fw8bY'><style id='fw8bY'><dir id='fw8bY'><q id='fw8bY'></q></dir></style></legend>

    <small id='fw8bY'></small><noframes id='fw8bY'>

    1. <i id='fw8bY'><tr id='fw8bY'><dt id='fw8bY'><q id='fw8bY'><span id='fw8bY'><b id='fw8bY'><form id='fw8bY'><ins id='fw8bY'></ins><ul id='fw8bY'></ul><sub id='fw8bY'></sub></form><legend id='fw8bY'></legend><bdo id='fw8bY'><pre id='fw8bY'><center id='fw8bY'></center></pre></bdo></b><th id='fw8bY'></th></span></q></dt></tr></i><div id='fw8bY'><tfoot id='fw8bY'></tfoot><dl id='fw8bY'><fieldset id='fw8bY'></fieldset></dl></div>
      • <bdo id='fw8bY'></bdo><ul id='fw8bY'></ul>

        如何用许多随机数填充 MySQL 表?

        时间:2023-06-26
          <tbody id='XEjrW'></tbody>
        <tfoot id='XEjrW'></tfoot>

          • <bdo id='XEjrW'></bdo><ul id='XEjrW'></ul>
            <i id='XEjrW'><tr id='XEjrW'><dt id='XEjrW'><q id='XEjrW'><span id='XEjrW'><b id='XEjrW'><form id='XEjrW'><ins id='XEjrW'></ins><ul id='XEjrW'></ul><sub id='XEjrW'></sub></form><legend id='XEjrW'></legend><bdo id='XEjrW'><pre id='XEjrW'><center id='XEjrW'></center></pre></bdo></b><th id='XEjrW'></th></span></q></dt></tr></i><div id='XEjrW'><tfoot id='XEjrW'></tfoot><dl id='XEjrW'><fieldset id='XEjrW'></fieldset></dl></div>

            <small id='XEjrW'></small><noframes id='XEjrW'>

              <legend id='XEjrW'><style id='XEjrW'><dir id='XEjrW'><q id='XEjrW'></q></dir></style></legend>

                  本文介绍了如何用许多随机数填充 MySQL 表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我要问一个在中被问到的问题非常抽象术语,带有(可以理解)没有提供具体的答案:

                  I'm going to ask a question that has been asked in very abstract terms, with (understandably) no concrete answers provided:

                  如何在 MySQL 提示下创建和填充表 rand_numbers,其中包含一列 number INT 和 1111 行,其中 number 列包含 2222 到 5555 之间的随机数?

                  From the MySQL prompt, how do I create and populate a table, rand_numbers, with one column, number INT, and 1111 rows, where the number column holds a random number between 2222 and 5555?

                  类似于:

                  CREATE TABLE rand_numbers(number INT);
                  
                   #run following line 1111 times
                  INSERT INTO rand_numbers (number) VALUES (2222 + CEIL( RAND() * 3333));
                  

                  这个问题已经有人问过了,但是依赖循环的外部语言或者过于笼统.我想知道是否可以从典型的 Linux MySQL 提示中执行如此简单的操作.

                  This question has been asked, but either relies on external languages for the loop or is far too general. I would like to know if it's possible to do something this simple from a typical Linux MySQL prompt.

                  推荐答案

                  创建表格使用:

                  CREATE TABLE rand_numbers (
                      number INT NOT NULL
                  ) ENGINE = MYISAM;
                  

                  然后用随机值填充它,你可以定义一个存储过程(它支持循环):

                  Then to populate it with random values, you can define a stored procedure (which supports looping):

                  DELIMITER $$
                  CREATE PROCEDURE InsertRand(IN NumRows INT, IN MinVal INT, IN MaxVal INT)
                      BEGIN
                          DECLARE i INT;
                          SET i = 1;
                          START TRANSACTION;
                          WHILE i <= NumRows DO
                              INSERT INTO rand_numbers VALUES (MinVal + CEIL(RAND() * (MaxVal - MinVal)));
                              SET i = i + 1;
                          END WHILE;
                          COMMIT;
                      END$$
                  DELIMITER ;
                  
                  CALL InsertRand(1111, 2222, 5555);
                  

                  然后您可以重用该过程以根据不同的参数插入更多随机值..假设 600 行的随机值介于 1200 和 8500 之间:

                  Then you can reuse that procedure to insert more random values based on different parameters.. say 600 rows with random values between 1200 and 8500:

                  CALL InsertRand(600, 1200, 8500);
                  

                  这篇关于如何用许多随机数填充 MySQL 表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MySQL:如何选择本周的记录? 下一篇:使用错误的mysql配置重置root密码

                  相关文章

                  <small id='W4vhs'></small><noframes id='W4vhs'>

                      <legend id='W4vhs'><style id='W4vhs'><dir id='W4vhs'><q id='W4vhs'></q></dir></style></legend>
                      • <bdo id='W4vhs'></bdo><ul id='W4vhs'></ul>

                      <tfoot id='W4vhs'></tfoot>
                      <i id='W4vhs'><tr id='W4vhs'><dt id='W4vhs'><q id='W4vhs'><span id='W4vhs'><b id='W4vhs'><form id='W4vhs'><ins id='W4vhs'></ins><ul id='W4vhs'></ul><sub id='W4vhs'></sub></form><legend id='W4vhs'></legend><bdo id='W4vhs'><pre id='W4vhs'><center id='W4vhs'></center></pre></bdo></b><th id='W4vhs'></th></span></q></dt></tr></i><div id='W4vhs'><tfoot id='W4vhs'></tfoot><dl id='W4vhs'><fieldset id='W4vhs'></fieldset></dl></div>