很简单一句话
if exists (select * from sysobjects
where id = object_id('dbo.aaa'))
drop table dbo.aaa
go
create table aaa(
pid int primary key,
tmpfield varchar(10)
)
go
if exists (select * from sysobjects
where id = object_id('dbo.bbb'))
drop table dbo.bbb
go
create table bbb(
pid int primary key,
tmpfield varchar(10)
)
go
insert aaa(pid, tmpfield) values(1,'sdga')
insert aaa(pid, tmpfield) values(2,'sd')
insert aaa(pid, tmpfield) values(3,'dgga')
insert aaa(pid, tmpfield) values(4,'sjja')
insert aaa(pid, tmpfield) values(5,'gha')
go
insert bbb(pid, tmpfield) values(1,'ok1')
insert bbb(pid, tmpfield) values(2,'ok2')
insert bbb(pid, tmpfield) values(3,'ok3')
insert bbb(pid, tmpfield) values(4,'ok4')
insert bbb(pid, tmpfield) values(5,'ok5')
go
select * from aaa
select * from bbb
go
update aaa set aaa.tmpfield=bbb.tmpfield from aaa, bbb where aaa.pid=bbb.pid
go
select * from aaa
select * from bbb
go