Knowledge Base

How can I do a mass find and replace in articles?

Article ID: 189
Last updated: 19 Dec, 2010

You can write one-line find-and-replace statements in SQL.
To find a string in a certain field and replace it with another string:

UPDATE [table_name] SET [field_name] = REPLACE([field_name],'[string_to_find]','[string_to_replace]');


To not affect date updated for the articles use following sql:

UPDATE [table_name] SET [field_name] = REPLACE([field_name],'[string_to_find]','[string_to_replace]'), date_updated=date_updated;


To find what articles will be affected:

SELECT [field] FROM [table_name] WHERE [field_name] LIKE '%[string_to_find]%';


Example: replace "apple" to "banana" in all articles

UPDATE kbp_kb_entry SET body = REPLACE(body,'apple','banana'), date_updated=date_updated;
Article ID: 189
Last updated: 19 Dec, 2010
Revision: 1
Access: Public
Views: 6236
Comments: 0