[thelist] SQL partial string replace

rudy r937 at interlog.com
Fri Jan 10 14:54:01 CST 2003


> I need to change the domain name for a bunch of email addresses in a
> MySQL database (asd.k12.ak.us -> asdk12.org)

UPDATE yourtable
  SET emailcolumn
     = REPLACE(emailcolumn,'asd.k12.ak.us','asdk12.org')
         WHERE emailcolumn like '%asd.k12.ak.us%'

http://www.mysql.com/doc/en/String_functions.html#IDX1189

the WHERE condition will choose the rows to update -- without it, you will
update every row in the table (most of them with the same value they were)

rudy




More information about the thelist mailing list