drop table test
if exists (select name from sysobjects where name='test1' and type='u')
drop table test1
create table test
(id int,name varchar(20))
insert into test values (1,'Who am i,test?')
create table test1
(id int,name varchar(20))
insert into test values (1,'Who am i,test1?')
update test set id=2 from test bsh where test.id=bsh.id
update test set id=2 from test bsh where id=bsh.id
update test set id=2 from test bsh,test sh where id=bsh.id and id=sh.id
update test1 set id=2 from test bsh,test sh where test1.id=bsh.id and
test1.id=sh.iddrop table test1
drop table test
原來UPDATE語句是可以更新別名的。比如可以這樣執行:
update bsh set id=2 from test bsh,test sh where bsh.id=sh.id
但爲什麼UPDATE test SET id=2 FROM test bsh,test sh爲報錯?這還是個疑問.