str_replace in SQL UPDATE?

Here’s a sample table:

name       |   picture

John S.    |
Linda B.   |

Let’s say there are several hundred more records.

Let’s also say we moved servers from “servera” to “serverb”.

Would it be possible to go into this table with one query to rename the content in the column “picture” for every record to read the correct server name?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1


update TBL 
   set picture = Replace(picture, 'servera', 'serverb') 
 where picture like '%servera%'


update TBL 
   set picture = replace(picture, 'servera', 'serverb') 
 where picture like '%servera%'


update TBL 
   set picture = REPLACE(picture, 'servera', 'serverb') 
 where picture like '%servera%'

Method 2

UPDATE users
SET picture = REPLACE(picture, '', '')
WHERE picture LIKE '';

I’m including more of the string because I’d worry about ‘fixing’ an image named ‘somethingserverasomething.jpg’. I might also think about having a base_url table and just storing image file names in users, but that’s not the question you asked 😉

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x