MYSQL存储过程 踩坑

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_32197439/article/details/83184590

存储过程该怎么写

  • 这周主要就在使用存储过程来修复线上数据
  • 使用工具
    • 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;

猜你喜欢

转载自blog.csdn.net/sinat_32197439/article/details/83184590