替换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'

 

posted on 2013-03-27 19:50  seaven  阅读(207)  评论(0编辑  收藏  举报

导航