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
  • 相关阅读:
    [引]Windows窗体编程基础学习: 对话框组件
    UML学习四:UML在微软的VS与Visio间的应用 VEA(Visio for Enterprise Architects)
    SQL查询 FOR XML [RAW|AUTO|EXPLICIT]
    微软企业类库:Enterprise Library for .NET Framework 2.0 January 2006
    自定义制作 自动定时更换图片的桌面背景 html页面
    [引]Windows Server 2003 : Windows 群集
    LOVE
    SQL Server Mobile 学习(三):SQL Server Mobile 远程数据访问(RDA)
    游戏分类
    [摘]UML学习二:标准建模语言UML的静态建模机制
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2941007.html
Copyright © 2011-2022 走看看