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

  • 相关阅读:
    python虚拟环境使用
    虚拟化网络进阶管理
    虚拟化进阶管理
    KVM虚拟化
    Xen虚拟化
    Virtualization基础
    Virnish使用
    CentOS配置FTP服务器
    Ajax结合Json进行交互数据(四)
    将 数据库中的结果集转换为json格式(三)
  • 原文地址:https://www.cnblogs.com/Denny_Yang/p/2220002.html
Copyright © 2011-2022 走看看