例如,Table1 定义为 (id int, address varchar(100))
将更新表中的每个值:
create table #test (id int, address varchar(100))
insert into #test (id, address)
values (5, 'test address')
update Table1
set
address = (select top 1 address from #test)
where exists (select 1 from #test t where id = t.id)
只会更新 id = 5 的条目:
create table #test (id2 int, address varchar(100))
insert into #test (id2, address)
values (5, 'test address')
update Table1
set
address = (select top 1 address from #test)
where exists (select 1 from #test t where id = t.id2)
唯一的区别似乎是一个临时表的 ID 与源表匹配,而另一个则没有。这有什么关系?或者这里发生了什么更微妙或更明显的事情?