准备脚本:
use master
go
if exists(select * from sysdatabases where name='test')
drop database test
go
create database test
go
use test
go
create table tab1
(
a varchar(10),
b varchar(10)
)
go
create table tab2
(
a varchar(10),
b varchar(10)
)
go
delete from tab1
delete from tab2
insert into tab1 values(1,0)
insert into tab1 values(2,0)
insert into tab1 values(3,0)
insert into tab2 values(1,1)
insert into tab2 values(2,2)
insert into tab2 values(3,3)
select * from tab1
select * from tab2
use master
go
if exists(select * from sysdatabases where name='test')
drop database test
go
create database test
go
use test
go
create table tab1
(
a varchar(10),
b varchar(10)
)
go
create table tab2
(
a varchar(10),
b varchar(10)
)
go
delete from tab1
delete from tab2
insert into tab1 values(1,0)
insert into tab1 values(2,0)
insert into tab1 values(3,0)
insert into tab2 values(1,1)
insert into tab2 values(2,2)
insert into tab2 values(3,3)
select * from tab1
select * from tab2
主要代码:
--连接updatge
update tab1 set tab1.b=tab2.b from tab1 inner join tab2 on tab1.a=tab2.a
--或 |