zoukankan      html  css  js  c++  java
  • SQL事务示例2个

    示例1:

    ALTER PROCEDURE dbo.newstapein 

    @program nvarchar(50), 
    @tapecode nvarchar(50), 
    @department nvarchar(50), 

    AS 
    /* SET NOCOUNT ON */  
    if Exists(select * from ttape where program = @program and tapecode = @tapecode) 
    begin 
      return -100 
    end 
    else
    begin
      begin transaction 
      insert into ttape(program,tapecode,department) values(@program,@tapecode,@department)
      if @@error=0  
      begin 
      declare @tapeid int ,@pubdate datetime
      select top 1 @tapeid=tapeid ,@pubdate=pubdate from ttape order by tapeid desc
      if @@row_count<>0
      insert into tnewstapedetail(tapeid,pubdate) values(@tapeid,@pubdate)
      commit transaction  
      end
      else  
      begin  
      rollback transaction  
      return -1 
      end
    end

    示例2:

    ALTER PROCEDURE [dbo].[AP_USER_UpdateCompanyList]
    AS
    BEGIN
     BEGIN TRANSACTION
     update AP_USER set CompanyList=dbo.GetDeptList_DY(DEPT_CODE)
     from DEPTCODE
     where WhichCompany=CONTENT
     and CHARINDEX('Z001',AuthList)>0
     and WhichCompany<>'集团本部'
     and UserName<>'admin'

     update AP_USER set CompanyList=dbo.GetDeptList_DY('01')
     from DEPTCODE
     where CHARINDEX('Z001',AuthList)>0
     and (WhichCompany='集团本部' or UserName='admin')
     if @@ERROR = 0 
      commit transaction
     else
      rollback transaction
    END

  • 相关阅读:
    win10通过ip连接打印机
    tarunexpectedeofinarchive
    软件工程设计阶段的几种图
    代码review checklist
    caffeine的使用
    thetrustanchorsparametermustbenonempty
    mysql explain type的详解
    scp对拷贝文件夹
    虚拟dom与diff算法
    线程池ThreadPoolExecutor的使用
  • 原文地址:https://www.cnblogs.com/Denny_Yang/p/2220002.html
Copyright © 2011-2022 走看看