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
  • 相关阅读:
    [pycharm]远程调试服务器项目
    [Linux]防火墙关闭与开启
    [Linux]安装pyenv
    [Linux]ubuntu安装基本流程
    [python]html格式转md格式
    [python]目录及文件操作
    [Linux]安装node.js
    Linux基础
    爬虫基础(3)
    爬虫基础(2)
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2941007.html
Copyright © 2011-2022 走看看