You could use a cursor and the sys.tables/sys.columns views to go through them. Give me a minute, and I'll give you the code.
Update: Here you are:
declare @col_name nvarchar(50)
declare @sql nvarchar(max)
declare @tbl_name nvarchar(50)
declare @old_str nvarchar(50)
declare @new_str nvarchar(50)
set @old_str = 'stakoverflow'
set @new_str = 'StackOverflow'
declare fetch_name cursor for
select
c.name,
t.name
from
sys.columns c
inner join sys.tables t on c.object_id = t.object_id
inner join sys.types y on c.system_type_id = y.system_type_id
where
y.name like '%varchar'
or y.name like '%text'
open fetch_name
fetch next from fetch_name into @col_name, @tbl_name
while @@fetch_status = 0
begin
set @sql = 'UPDATE ' + @tbl_name + ' SET ' +
@col_name + ' = replace(' +
@col_name + ',''' +
@old_str + ''',''' +
@new_str + ''')'
exec sp_executesql @sql
fetch next from fetch_name into @col_name
end
close fetch_name
deallocate fetch_name
This will get you everything you need. It grabs the columns that are varchar, nvarchar, text, and ntext from your database, cycle through the columns and update each one.
Of course, you could also do this to create a concatenated SQL statement and do one big update at the end, but hey, that's your preference.
And for the record, I don't like cursors, but since we're dealing with a few columns and not millions of rows, I'm okay with this one.