I agree with Ben...this is something that you should be running in SQL
Management Studio. ColdFusion is not meant to run this kind of stuff
(unless you set the timeout on your templates to 0). The code attached
below will loop over all of the user tables, and then loop over all of the
text type columns for that table while writing out an update statement.
Send your results to Text in the query window. Then you can cut and paste
the text results into a new query window and run it. Make sure you change
the text values to be changed and what they are going to be changed to.
Also, if your tables follow a naming convention, you can add that to the
first cursor declaration as an additional where clause...
DECLARE @tableName NVARCHAR(255), @objectID BIGINT, @columnName
NVARCHAR(255),
@TextToReplace NVARCHAR(1000), @ReplaceTextWith NVARCHAR(1000)
SET @TextToReplace = '
www.mysite.com'
SET @replaceTextWith = '
www.mynewsite.com'
DECLARE userTables CURSOR FOR
SELECT name, object_id FROM sys.tables WHERE [type] = 'U'
OPEN userTables
FETCH NEXT FROM userTables
INTO @tableName, @objectID
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'UPDATE ' + @tableName + ' SET '
/*
Select the columns from the table where the data type is a text type
column
Text - 35
sql_variant - 98
ntext - 99
varchar - 167
char - 175
nvarchar - 231
nchar - 239
*/
DECLARE userColumns CURSOR FOR
SELECT name FROM sys.columns WHERE object_id = @objectID AND
system_type_id IN (35,98,99,167,175,231,239)
OPEN userColumns
FETCH NEXT FROM userColumns
INTO @columnName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT '[' + @columnName + '] = REPLACE([' + @columnname + '], ''' +
@TextToReplace + ''', ''' + @ReplaceTextWith + '''),'
FETCH NEXT FROM userColumns
INTO @columnName
END
CLOSE userColumns
DEALLOCATE userColumns
PRINT '1=1'
PRINT 'GO'
PRINT ' '
FETCH NEXT FROM userTables
INTO @tableName, @columnName
END
CLOSE userTables
DEALLOCATE userTables
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:357847