一个存储过程实现增删操作

数据库
数据库存储过程中的增删操作时经常会用到的,下文将主要为大家介绍数据库中存储过程中的增删操作。

--存储过程的功能:对表 UBS_CAS_PriceFormBatch 进行添加、更新、删除、获取操作。
--参数说明:

 /*
  @DataAction 添加更新删除的标志位
  @ID ID
  @BatchNo ('批次号')
  @ItemClassID 分类
  @PurchaserUID 分类
  @AuditorUID 批准人
  @CheckerUID 审核者
  @PubDate 拟制时间
  @CheckDate 审核时间
  @PassDate 批准时间
  @State 表单状态
  @FormType 表单类型
  @SupplierCode 供应商代码
  @CompanyType 厂别
  @InputModelMaterial 输入成本模型的物料
  @Purchaser
  @Auditor
  @Checker
  @RejectReason
  */
  Create PROCEDURE UBS_CAS_PriceFormBatchAction
  @DataAction int,
  @ID int = 0,
  @BatchNo varchar(50),
  @ItemClassID int,
  @PurchaserUID int,
  @AuditorUID int,
  @CheckerUID int,
  @PubDate datetime,
  @CheckDate datetime,
  @PassDate datetime,
  @State int,
  @FormType int,
  @SupplierCode varchar(50),
  @CompanyType int,
  @InputModelMaterial varchar(50),
  @Purchaser varchar(50),
  @Auditor varchar(50),
  @Checker varchar(50),
  @RejectReason varchar(500)
  AS
  begin tran
  SET NOCOUNT ON
  if @DataAction=0
  begin
  insert into UBS_CAS_PriceFormBatch
  (
  [BatchNo],
  [ItemClassID],
  [PurchaserUID],
  [AuditorUID],
  [CheckerUID],
  [PubDate],
  [CheckDate],
  [PassDate],
  [State],
  [FormType],
  [SupplierCode],
  [CompanyType],
  [InputModelMaterial],
  [Purchaser],
  [Auditor],
  [Checker],
  [RejectReason]
  )
  values
  (
  @BatchNo,
  @ItemClassID,
  @PurchaserUID,
  @AuditorUID,
  @CheckerUID,
  @PubDate,
  @CheckDate,
  @PassDate,
  @State,
  @FormType,
  @SupplierCode,
  @CompanyType,
  @InputModelMaterial,
  @Purchaser,
  @Auditor,
  @Checker,
  @RejectReason
  )
  set
  @ID=scope_identity()
  end
  if @DataAction=1
  begin
  Update [UBS_CAS_PriceFormBatch] SET
  [BatchNo] = @BatchNo,
  [ItemClassID] = @ItemClassID,
  [PurchaserUID] = @PurchaserUID,
  [AuditorUID] = @AuditorUID,
  [CheckerUID] = @CheckerUID,
  [PubDate] = @PubDate,
  [CheckDate] = @CheckDate,
  [PassDate] = @PassDate,
  [State] = @State,
  [FormType] = @FormType,
  [SupplierCode] = @SupplierCode,
  [CompanyType] = @CompanyType,
  [InputModelMaterial] = @InputModelMaterial,
  [Purchaser] = @Purchaser,
  [Auditor] = @Auditor,
  [Checker] = @Checker,
  [RejectReason] = @RejectReason
  Where
  [ID] = @ID
  end
  if @DataAction=2
  begin
  delete from [UBS_CAS_PriceFormBatch] where [ID] = @ID
  end
  if @DataAction=3
  begin
  select
  [BatchNo],
  [ItemClassID],
  [PurchaserUID],
  [AuditorUID],
  [CheckerUID],
  [PubDate],
  [CheckDate],
  [PassDate],
  [State],
  [FormType],
  [SupplierCode],
  [CompanyType],
  [InputModelMaterial],
  [Purchaser],
  [Auditor],
  [Checker],
  [RejectReason],
  from [UBS_CAS_PriceFormBatch]
  where
  [ID] = @ID
  end
  if @@error<>0 goto sqlerr
  commit tran
  return
  sqlerr:
  rollback
  SET NOCOUNT OFF
  GO

上文中的内容主要是以代码的形式展现出来的,对于刚入门的初学者可能比较难理解,希望大家都能很好的掌握这些知识,为大家以后工作带来方便。

【编辑推荐】

  1. SQL Server 存储过程的分页
  2. 使用存储过程都有哪些益处
  3. 四种利用固态存储补充存储系统的方式
责任编辑:迎迎 来源: 博客网
相关推荐

2016-12-20 10:59:43

MySQL存储insert

2010-04-15 17:45:26

Oracle存储过程

2011-07-18 15:08:19

SQL存储过程

2011-05-17 15:13:59

oracle分页存储

2009-09-17 10:40:23

linq存储过程

2010-04-16 13:22:39

OracleJavaP

2011-12-26 16:39:43

局部函数

2011-06-30 09:37:08

JavaDB2SQL

2011-07-29 13:21:31

CTE递归存储过程真分页

2011-07-22 15:38:54

SQL Server数存储过程切割字符串

2021-06-30 07:19:36

网络安全

2020-12-02 12:29:24

Vue无限级联树形

2023-12-31 16:35:31

Pytorch函数深度学习

2010-10-12 10:48:02

mysql存储过程

2011-08-29 14:33:02

Oracle存储过程

2010-11-29 09:12:46

sybase分页存储过

2011-07-21 16:28:20

MySQL数据库带游标的存储过程

2011-08-12 14:01:21

SQL Server存储过程

2022-08-02 14:21:20

滑动验证码鸿蒙

2020-09-24 11:46:03

Promise
点赞
收藏

51CTO技术栈公众号