update a set typeid=b.typeid from a inner join b on A.content=B.content--or update a set typeid=b.typeid from b where A.content=B.content
update 表A set 表A.typeid=表B.typeid from 表B where 表A.content=表B.content
update A set A.typeid=B.typeid from B where A.content=B.content
---测试数据--- if object_id('[A]') is not null drop table [A] go create table [A]([id] int,[typeid] int,[content] varchar(6)) insert [A] select 1,2,'adasd' union all select 2,3,'dfadsf' union all select 3,4,'dafd' if object_id('[B]') is not null drop table [B] go create table [B]([typeid] int,[content] varchar(6)) insert [B] select 9,'adasd' union all select 8,'dfadsf' union all select 7,'dafd'
---更新--- update A set A.typeid=B.typeid from B where A.content=B.content---查询--- select * from A---结果--- id typeid content ----------- ----------- ------- 1 9 adasd 2 8 dfadsf 3 7 dafd(所影响的行数为 3 行)
update a
set typeid=b.typeid
from a
inner join b on A.content=B.content--or
update a
set typeid=b.typeid
from b
where A.content=B.content
update 表A
set 表A.typeid=表B.typeid
from 表B
where 表A.content=表B.content
set A.typeid=B.typeid
from B
where A.content=B.content
if object_id('[A]') is not null drop table [A]
go
create table [A]([id] int,[typeid] int,[content] varchar(6))
insert [A]
select 1,2,'adasd' union all
select 2,3,'dfadsf' union all
select 3,4,'dafd'
if object_id('[B]') is not null drop table [B]
go
create table [B]([typeid] int,[content] varchar(6))
insert [B]
select 9,'adasd' union all
select 8,'dfadsf' union all
select 7,'dafd'
---更新---
update A
set A.typeid=B.typeid
from B
where A.content=B.content---查询---
select * from A---结果---
id typeid content
----------- ----------- -------
1 9 adasd
2 8 dfadsf
3 7 dafd(所影响的行数为 3 行)