[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>前言
在项目开发中,经常会遇到这样一种场景,当修改A表的一条数据时,需要关联修改B表、C表甚至其他更多表的数据,为什么会这样呢?
在真实的业务场景中,往往一张表的数据关联的业务是多样的,举例来说,用户在页面上完成一个订单,对服务端来说,与这个订单相关的业务还有很多,比如生成一条出库记录,扣减库存,用户的账户余额扣减,商家的账户余额增加,财务结算等等…
所有这些不同的业务员操作,在服务端来说,最终体现的就是与数据库的交互,可想而知,假如关联的业务越复杂,需要与数据库进行IO的次数就越多;
那么有没有什么办法,在面对此类场景业务时,提升服务端的性能,减少数据库IO呢?这就是本篇将要分享的存储过程。
<>什么是存储过程
存储过程就是事先经过编译并存储在数据库中的一段 SQL 语句的集合;
<>为什么使用存储过程
调用存储过程可以简化应用开发人员的很多工作,减少数据在数据库和应用服务器之间的传输,对于提高数据处理的效率是有好处的。存储过程思想上很简单,就是数据库
SQL 语言层面的代码封装与重用。
存储过程特点:
* 封装,复用, 可以把某一业务SQL封装在存储过程中,需要用到的时候直接调用即可;
* 可以接收参数,也可以返回数据, 在存储过程中,可以传递参数,也可以接收返回值;
* 减少网络交互,提升