Home  >  Article  >  Database  >  替换SQL Server数据库中所有表的所有字段的某些内容--方法一

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

WBOY
WBOYOriginal
2016-06-07 14:54:481358browse

替换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(''+quot

替换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'
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn