update doc set id=1 where id is nulldeclare @id int
set @id=1
update doc set @id=id=@id+1

解决方案 »

  1.   

    declare @A int,@B intupdate 
        T 
    set 
        @B = case when @A=A then @B+1 else 0 end,
        B  = @B,
        @A = A
      

  2.   

    数据库学的不怎么好,看了一下,不懂,
    碰到这个问题,想请教下大家,alter database xscj
      modify name=JUST_TEST消息栏出错说:
    服务器: 消息 5030,级别 16,状态 2,行 1
    未能排它地锁定数据库以执行该操作。先谢了
      

  3.   

    --看例子:
    Create table #(ID int,value varchar(10))
    insert into # select NULL,'a'
    union all select NULL,'b'
    union all select NULL,'c'
    union all select NULL,'d'--更新
    update #
    set ID=(select count(1) from # where value<=A.value) 
    from # A--结果 select * from #ID          value      
    ----------- ---------- 
    1           a
    2           b
    3           c
    4           d(所影响的行数为 4 行)