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

  • 相关阅读:
    poll系统调用的内核态实现机制分析
    Tomcat与web程序结构与Http协议
    关于java的环境变量的一点总结
    我想成为大牛,第一队,不要单打独斗
    ubuntu12.04单卡server(mentohust认证)再加上交换机做路由软件共享上网
    写在程序猿的困惑(特别Java程序猿)入行一年,感觉我不知道接下来该怎么办才能不断进步的,寻求翼
    三大趋势在移动互联网发展
    031 二进制1的数量(keep it up, 看到这个问题,刚开始有点蒙)
    【Java】【Flume】Flume-NG阅读源代码AvroSink
    PHP中间uniqid在高并发重复问题
  • 原文地址:https://www.cnblogs.com/Thenext/p/9635364.html
Copyright © 2011-2022 走看看