Mysql迴圈insert資料

2022-07-06 23:48:16 字數 1177 閱讀 8396

開發自測時,資料庫需要造大量資料時,要用到mysql儲存過程相關知識,下面分享下,希望對小夥伴們有所幫助:

create

procedure

test() #建立儲存函式;

begin

declare i int

default1;

while i <

5000

do#下面的insert語法要改成自己的表,同時構造value.id,要考慮防重;

insert

into `wbms_1`.`waybill_weight_volume_2`(`id`, `tenant_id`, `waybill_code`, `operate_code`, `volume`, `weight`, `length`, `width`, `height`, `weight_time`, `volume_time`, `ope_type`, `operator_code`, `operator_name`, `operate_station_code`, `operate_station`, `is_delete`, `create_time`, `update_time`, `create_user`, `update_user`, `ts`) values (1356063857646284800

+i, '

test

', '

zy1000502218621

', '

zy1000502218621-1-2-

', 55.0000, 55.0000, 5.5000, 55.0000, 55.0000, '

2020-09-20 16:39:56

', '

2020-09-20 16:39:56

', 3, '

21180252

', '

陳青山', '

308766

', '

南京江駿營業部

', 0, '

2021-02-01 10:16:32

', '

2021-02-01 10:16:32

', null, null, '

2021-02-01 10:16:32.000');

set i = i+1;

endwhile

;end

;call test();#呼叫儲存函式

MySQL必知必會 資料插入(Insert)

本篇文章介紹如何使用insert語句將資料插入到資料庫。增刪改查是資料庫最常用的4個命令,插入算是第二常用,第一是select。插入資料的方式大概有4種 插入完整的行 插入行的一部分 插入多行資料 批量插入 插入來自查詢的資料 使用insert將一條資料插入資料庫是最簡單也是最基本的操作。插入操作有...

insert 插入資料

語法格式 insert into 表名稱 欄位名稱1,欄位名稱2 values 值1,值2,建立備份表myemp create table myemp as select from emp 標準語法 對於沒有資料的列就不寫進欄位列表 insert into myemp empno,ename,job...

插入資料 INSERT

顧名思義,insert是用來插入行到資料庫表的 插入可以用幾種方式使用 插入完整的行 插入行的一部分 插入多行 插入某些查詢結果 分析 此例子為插入乙個新客戶到customers表,如果某個列沒有值,應該使用null 表允許該值為空 第一列cust id也為null,因為這是自動增量 上面的語法很簡...