22,209
社区成员
发帖
与我相关
我的任务
分享
create table tb1(ArrID int,ArrName nvarchar(10))
insert into tb1 select 1,'北京' union all select 2,'上海' union all select 3,'广东'
create table tb2(ArrName nvarchar(10),ArrID int)
insert into tb2(ArrName) select '上海' union all select '广东' union all select '上海' union all select '北京'
go
update tb2 set ArrID=b.ArrID from tb2 a inner join tb1 b on a.ArrName=b.ArrName
select * from tb2
go
drop table tb1,tb2
/*
ArrName ArrID
---------- -----------
上海 2
广东 3
上海 2
北京 1
(4 行受影响)
*/