MySql資料庫的最佳化(一) 資料的迴圈添加

來源:互聯網
上載者:User

標籤:code   sql   建立   資料庫   語句   bit   data   alt   執行函數   

這兩天在做代碼的最佳化。需要十萬、百萬甚至更多的資料。這時候顯然一條一條的添加是不現實的,這時候就用到了迴圈添加的語句。

第一步,在做迴圈添加的時候我們需要先建一個測試的資料庫temp_mysql_DataTesting;

create DATABASE temp_mysql_DataTesting;

第二步,開啟temp_mysql_DataTesting資料庫建立資料表temp_mysql_data;

create table temp_mysql_data
(
  Id INT primary key auto_increment,
  Email varchar(50) null comment ‘使用者郵箱‘,
  EmailConfirmed bit not null comment ‘是否認證郵箱‘,
  PhoneNumber varchar(100) null comment ‘使用者手機‘,
  LastLoginTime datetime null comment ‘最後登入時間‘,
  FirstLoginTime datetime null comment ‘第一次登入時間‘,
  CreateTime datetime null comment ‘建立時間‘
) comment ‘測試資料表‘;

第三步,條件準備好之後,開始迴圈添加語句;

CREATE PROCEDURE proc_while_insert()  /*建立一個函數*/BEGINDECLARE num INT;SET num = 0;WHILE num < 300000 DO/*添加數量*//*添加語句,最後一英文分號;結束*/SET num = num + 1 ;END WHILE;END;

先執行函數,然後找到函數,執行函數。函數位置,

 

MySql資料庫的最佳化(一) 資料的迴圈添加

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.