update b
set memo = a.name
from a,b
where a.id = b.id
这个就是只更新from内的结果集,等效于下面的sql:
update b set memo=(select max(a.name) from a where a.id=b.id)
where exists(select 1 from a where a.id=b.id);
实际上这两条语句都需要name和id是一一对应的,id是主码。
Oracle中是不支持update:From这样的句子的,ms-sql支持的,所以还是少用这种东西的好,不至于以后在两种数据库中犯迷糊。
事例1:
update DealerInfo set DealerType=@userType,DealerName=@DealerName from DealerUser
where DealerInfo.dealerId=DealerUser.DealerId and DealerUser.UserId=@UserId
事例2:
update a2.Admin set username=aaa.name,Levele='修改的系统管理员' from aaa
where a2.Admin.Aid=aaa.id and aaa.id=2
事例3
update a2.Admin set username='999',Levele='修改的系统管理员' from a2.Admin INNER JOIN dbo.aaa ON
a2.Admin.Aid=aaa.id where aaa.id=2