在更新表時,必須有鎖表動作
lock

解决方案 »

  1.   

    --测试一下,在一查询分析器里输入:
    begin tran
    declare @str int
    select @str=max(id) from .....
    insert into sdfsdf (...) values (...)
    commit tran
    ---然后在另几个查询分析器(或不同机器)里输入如上代码,运行出结果就知道了
      

  2.   

    例: if lock(talbe) then
           msgbox("資料表被鎖,請稍後再試.")
        else
           update table .....
        endif
      

  3.   

    如果在程序里,也可以,比如asp
    cn.begintransaction
    rs.open "select max(id) from ..."......
    .......
    if err<>0 then
    cn.rollback
    else
    cn.commite
    end if
      

  4.   

    掉了一個not.
    if lock(talbe) then
           msgbox("資料表被鎖,請稍後再試.")
        else
           update table .....
        endif
      

  5.   

    应该用事务来处理并发操作,因为一个事务必须完成才能进行其它事务,这就保证了在事务时间取单号内不会存在相同的问题,但不提倡用锁表来防止并发操作,这样会大幅降低效率.
    begin tran
    declare @str int
    select @str=max(id) from .....
    insert into sdfsdf (...) values (...)
    commit tran
      

  6.   

    我把数据库技术基础知识分为5大类:SQL、索引、查询规划、事务处理、分布式处理。每一个部分,都非常复杂。
      

  7.   

    把这个字段设成关键字,试着向数据库里写你找到的最大ID,出错最找一次,再写!
    如Delphi
    Pass:=False;
    while not Pass then
    Try
      insert into .... values (maxID....)
      Pass:=True;
     except 
      maxId:=maxId + 1;
    end