--当然,你可以通过系统表来生成update语句,不用逐个字段写
declare @s nvarchar(4000)
set @s=''
select @s=@s+',['+name+']=b.['+name+']'
from syscolumns
where id=object_id('表A')
and name not in('id','name')
set @s=stuff(@s,1,1,'')
exec('update a set '+@s+'
from 表A a,表A b
where a.id=1 --被更新的id
and b.id=2 --更新的源数据记录的id')
declare @s nvarchar(4000)
set @s=''
select @s=@s+',['+name+']=b.['+name+']'
from syscolumns
where id=object_id('表A')
and name not in('id','name')
set @s=stuff(@s,1,1,'')
exec('update a set '+@s+'
from 表A a,表A b
where a.id=1 --被更新的id
and b.id=2 --更新的源数据记录的id')
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货