--创建测试环境
set nocount on
go
create table A
(
ID int primary key,
name varchar(20)
)
insert A(ID,name) select 1,null union all select 2,null union all select 3,null
--更新以前
select * from A
select identity(int,10000,1) [tmp],* into # from A
update A set [name]=B.tmp from A join # B on B.[ID]=A.[ID]
drop table #
--更新以后
select * from A
--删除测试环境
drop table A
--结果
/*
ID name
----------- --------------------
1 NULL
2 NULL
3 NULL
ID name
----------- --------------------
1 10000
2 10001
3 10002
*/