在线等,盼望有高手指点一下!

解决方案 »

  1.   

    在读取数据加行锁,并且是排他锁,不能让其他用户读取你要更新的数据。
      

  2.   

    /*建立测试数据*/
    create table ordernum( num int)
    go
    insert ordernum values(0)
    go
    /*建立定单自动生成*/
    create procedure p_create_order(@orderno int output)
    as
    begin
    declare @i_maxnum int
    set nocount on
    begin tran
    select @i_maxnum = isnull(num,0) from ordernum with(UPDLOCK) /*UPDLOCK记录在事物未提交前不能被更新*/
    update ordernum set num = @i_maxnum + 1
    commit tran
    set @orderno = @i_maxnum + 1
    return 1
    end--调用
    declare @i_orderno int
    exec p_create_order @i_orderno output
    print(@i_orderno)
    drop table ordernum
    drop procedure p_create_order