一、建立批量更新儲存過程
create procedure update_edge_charge_status()begin
/* * 更新門禁收費狀態.
*/-- 1.建立臨時表
create temporary table unit_tmp as
select
unit.id,unit.status
from
unit unit
where
now() > unit.end_date and unit.status = 1;
-- 2.在臨時表中新增主鍵索引
alter table unit_tmp add primary key (`id`);
-- 3.將臨時表中的資料更新為欠費狀態
update unit_tmp set status = 2;
-- 4.級聯更新
update unit
inner join unit_tmp on unit.id = unit_tmp.id
set unit.status = unit_tmp.status;
end
二、執行存錯過程
call update_edge_charge_status();
通過建立臨時錶用主鍵索引來批量更改表資訊,安全係數較高,執行速度快,不會影響原表的使用。
mysql 儲存過程批量更新
最近做乙個批量更新的操作,由於是臨時需求,就想著在資料庫直接操作,不在 裡動手了,結合網上的一些資料,做如下處理 1.先建立乙個臨時表,匯入需要變動的資料 drop table if exists t barcode create table t barcode barcode varchar 32...
儲存過程批量更新
批量更新 mysql更新語句很簡單,更新一條資料的某個字段,一般這樣寫 複製 如下 update mytable set myfield value where other field other value 如果更新同一欄位為同乙個值,mysql也很簡單,修改下where即可 複製 如下 upda...
MYSQL批量建立表的儲存過程
因為業務需要,建立了100個表,但是這些表的結構都是一樣的,作為程式設計師,就是要解決這種重複勞動。然而這種事情還要單獨寫個php指令碼的話太麻煩了吧,所以就乾脆學了一下直接用mysql儲存過程怎麼實現 首先是建立表的 lpad i 2,0 的作用 是將1,2,3這些數字轉化為 01 02 03 d...