再再再问个简单的问题: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]
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]
(
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)
set id = b.id
from #t b where id = b.id - 2这个语句一行都没有更新
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)
同时又是自身表,能有什么效果?
set id = b.id
from #t b where id = b.id - 2
这句其实就相当于:
update #t
set id = id
where根本不起作用
set id = b.id
from #t b where 1 = 2
一条记录都找不到。
update #t
set n = b.ID
from #t b where id = b.id - 2
相当于update #t
set n = ID
为何也不起作用?