zoukankan      html  css  js  c++  java
  • 自动生成单据编号

    专门设计一个数据表用于存放管理软件中各种单据的最新的单据编号。编写一个存储过程用于自动生成单据编号。

     

    --****************
    --计算id

    --使用//表级排它锁//防止用户同时修改该记录
    --****************
    CREATE PROCEDURE GetId
    @xh integer,
    @id integer out
    AS
    /*
    如果想在连接一中锁住整个表,不允许其他事务更新表中任何记录,但可以读取记录,可使用HOLDLOCK选项,即(HOLDLOCK   等同于   SERIALIZABLE)  

    sql server 对并发的处理由它本身的锁控制,貌似并发,其实有等待排队的现象,只不过时间间隔短,所以并发数很多的时候,还是得进行人工锁设计

    在数据集上放置一个范围锁,以防止其他用户在事务完成之前更新数据集或将行插入数据集内。这是四个隔离级别中限制最大的级别。因为-发级别较低,所以应只在必要时才使用该选项。

    如果想在连接中锁住整个表,不允许其他事务更新表中任何记录甚至读取表中任何记录,可使用TABLOCKX选项,

    如果想在连接中不锁定表,允许其他事务更新表中任何行,使用NOLOCK选项


    */
        SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
        if @xh=1
          begin
            select @id=id from dbo. 编号材料销售
            set @id=@id+1
            update dbo.编号材料销售 with (TABLOCKX) set id=@id
          end
       else if @xh=2
          begin
            select @id=id from dbo.编号设置材料
            set @id=@id+1
            update dbo.编号设置材料 with (TABLOCKX) set id=@id
          end
       else if @xh=3
          begin
            select @id=id from dbo.编号工程结算
            set @id=@id+1
            update dbo.编号工程结算 with (TABLOCKX) set id=@id
          end
      else if @xh=4
          begin
            select @id=id from dbo.编号申请书
            set @id=@id+1
            update dbo.编号申请书 with (TABLOCKX) set id=@id
          end
      else if @xh=5
          begin
            select @id=id from dbo.编号合同书
            set @id=@id+1
            update dbo.编号合同书 with (TABLOCKX) set id=@id
          end
      else if @xh=6
          begin
            select @id=id from dbo.编号工程概算
            set @id=@id+1
            update dbo. 编号工程概算 with (TABLOCKX) set id=@id
          end  
       else if @xh=7
          begin
            select @id=id from dbo.编号采购清单
            set @id=@id+1
            update dbo.编号采购清单 with (TABLOCKX) set id=@id
          end
      else if @xh=8
          begin
            select @id=id from dbo.编号材料入库
            set @id=@id+1
            update dbo.编号材料入库 with (TABLOCKX) set id=@id
          end
      else if @xh=9
          begin
            select @id=id from dbo.编号零售材料
            set @id=@id+1
            update dbo.编号零售材料 with (TABLOCKX) set id=@id
          end
      else if @xh=10
          begin
            select @id=id from dbo. 编号升溢损耗
            set @id=@id+1
            update dbo.编号升溢损耗 with (TABLOCKX) set id=@id
          end
      else if @xh=11
          begin
            select @id=id from dbo.编号零星维修
            set @id=@id+1
            update dbo.编号零星维修 with (TABLOCKX) set id=@id
          end  

     COMMIT TRANSACTION

    GO

  • 相关阅读:
    Python
    Python
    Python
    Python
    Python
    《The Rise and Fall of Scala》scala的兴衰
    Scala核心编程_第05章_函数式编程
    IntelliJ IDEA scala的源码设置
    Scala核心编程_第04章 程序流程控制
    Scala核心编程_第03章_运算符
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2940731.html
Copyright © 2011-2022 走看看