这类似于 Sean Lange 的答案,但它解析为每个表一次更新,而不是每列一次更新。
--declare @schema nvarchar(256) = 'dbo';
--declare @table nvarchar(256) = 'table';
declare @sql nvarchar(max) = '';
set @sql += (select 'update '+t.table_schema+'.'+t.table_name+' set ' +stuff(
( select ', ['+i.column_name +']=replace(replace(['+i.column_name+'],char(10),''''),char(13),'''')'+char(10)
from information_schema.columns i
where i.table_schema=t.table_schema
and i.table_name=t.table_name
and i.data_type in ('char','nchar','varchar','nvarchar','text','ntext')
order by i.ordinal_position
for xml path('')),1,1,'')+';'+char(10)
from information_schema.tables t
where t.table_type='base table'
--and t.table_schema = @schema
--and t.table_name = @table
for xml path (''), type).value('.','varchar(max)')
--print @sql
select @sql
--exec sp_executesql @sql