再再再问个简单的问题:2个更新的语句。效果一样吗?为什么
code=SQL]
create table #t
(
id int,
n varchar(10)
)insert #t select 1,'ss'
insert #t select 3,'dd'
insert #t select 5,'xx'
insert #t select 6,'zz'
insert #t select 7,'dfd'
insert #t select 10,'name'
update #t 
set id = b.id 
from #t b where id = b.id - 2
update A
set a.id = b.id 
from #t A join #T b 
on(A.id = b.id -2)[[/code]

解决方案 »

  1.   

    额 没有颜色create table #t
    (
    id int,
    n varchar(10)
    )insert #t select 1,'ss'
    insert #t select 3,'dd'
    insert #t select 5,'xx'
    insert #t select 6,'zz'
    insert #t select 7,'dfd'
    insert #t select 10,'name'
    update #t  
    set id = b.id  
    from #t b where id = b.id - 2
    update A
    set a.id = b.id  
    from #t A join #T b  
    on(A.id = b.id -2)
      

  2.   

    update #t  
    set id = b.id  
    from #t b where id = b.id - 2这个语句一行都没有更新
      

  3.   

    --这个语句没错,但没有效果。
    update #t  
    set id = b.id  
    from #t b where id = b.id - 2--这个语句有错,没有表A,你的A是个别名。
    update A
    set a.id = b.id  
    from #t A join #T b  
    on(A.id = b.id -2)--更改为这样才行
    update #t
    set id = b.id  
    from #t A join #T b  
    on(A.id = b.id -2)
      

  4.   

    set id = b.id   
    同时又是自身表,能有什么效果?
      

  5.   

    update #t  
    set id = b.id  
    from #t b where id = b.id - 2
    这句其实就相当于:
    update #t  
    set id = id  
    where根本不起作用
      

  6.   

    没有错,大小写不敏感的话可以这样写第一句相当于 :update #t   
    set id = b.id   
    from #t b where 1 = 2
    一条记录都找不到。
      

  7.   

    按楼上的说法,
    update #t 
    set n = b.ID 
    from #t b where id = b.id - 2
    相当于update #t 
    set n = ID 
    为何也不起作用?