SQL: Find & Replace text in all records

On type of query I always have to run when moving a website from its test environment to its live environment is to replace the test domain in all content pages with the live domain. With SQL this can be easily done with the REPLACE(text, search, substitution) function.

For example:

UPDATE some_table
SET some_field = REPLACE(some_field, 'test.example.com', 'example.com')

This updates all records in the table some_table and replaces test.example.com with example.com in the field some_field.

Knowing which SQL functions exist can really help a lot and save time to update data.

Scroll to Top