Find and Replace Values in All Tables and All Text Columns using SQL Server
DECLARE @stringToFind VARCHAR ( 100 ) DECLARE @stringToReplace VARCHAR ( 100 ) DECLARE @schema sysname DECLARE @table sysname DECLARE @count INT DECLARE @sqlCommand VARCHAR ( 8000 ) DECLARE @where VARCHAR ( 8000 ) DECLARE @columnName sysname DECLARE @object_id INT SET @stringToFind = 'Smith' SET @stringToReplace = 'Jones' DECLARE TAB_CURSOR CURSOR FOR SELECT B . NAME AS SCHEMANAME , A . NAME AS TABLENAME , A . OBJECT_ID FROM sys . objects A INNER JOIN sys . schemas B ON A . SCHEMA_ID = B . SCHEMA_ID WHERE TYPE = 'U' ORDER BY 1 OPEN TAB_CURSOR FETCH NEXT FROM TAB_CURSOR INTO @schema , @table , @object_id
Read more →