存储过程该怎么写
- 这周主要就在使用存储过程来修复线上数据
- 使用工具
- Navicat 创建存储过程
- mysql
开始踩坑
-
一开始不知道存储过程有专门的操作界面
-
创建临时表
-
insert into tmp1(…) select * …
-
一定使用别名而非表名
-
对应的字段一 一对上
-
有更新和插入的地方 开启mysql 事务
- start transaction;
- commit;
-
插入临时表前先 truncate table tmp1;
CREATE PROCEDURE `p1`()
BEGIN
start transaction;
#1创建临时表1
drop table if exists tmp1;
create temporary table tmp1(
p1_order_id int(11),
p1_prepackage_product_id int(11),
p1_pl_id int(11),
p1_task_id int(11),
p1_validity int(11));
insert into tmp1 select ....
commit;
END;