替换SQL Server数据库中所有表的所有字段的某些内容

exec   sp_msforeachtable   @command1=N'   

  declare   @s   nvarchar(4000),@tbname   sysname   

  select   @s=N'''',@tbname=N''?''   

  select   @s=@s+N'',''+quotename(a.name)+N''=replace(''+quotename(a.name)+N'',N''''aa'''',N''''bb'''')''   

  from   syscolumns   a,systypes   b   

  where   a.id=object_id(@tbname)     

  and   a.xusertype=b.xusertype   

  and   b.name   like   N''%char''   

  if   @@rowcount>0   

  begin   

  set   @s=stuff(@s,1,1,N'''')   

  exec(N''update   ''+@tbname+''   set   ''+@s)   

  end'

 

你可能感兴趣的:(SQL Server)