mySQL将替换所有字符串,而不管字段名如何?

mySQL将替换所有字符串,而不管字段名如何?,mysql,Mysql,我有这个查询,但我想更改找到的每个字段\u name中的字符串,而不是手动更改。 我怎么能做到 update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’); 然后必须指定所有字段名。范例 UPDATE tableName SET field1 = REPLACE(field1, 'oldstring', 'newst

我有这个查询,但我想更改找到的每个字段\u name中的字符串,而不是手动更改。 我怎么能做到

update TABLE_NAME 
set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);

然后必须指定所有字段名。范例

UPDATE tableName
   SET field1 = REPLACE(field1, 'oldstring', 'newstring'),
       field2 = REPLACE(field2, 'oldstring', 'newstring'),
       field3 = REPLACE(field3, 'oldstring', 'newstring'),
       fieldN = REPLACE(fieldN, 'oldstring', 'newstring')

您可以使用
information\u schema.columns
为每列构建查询

SELECT CONCAT( 'Update table ', table_name, 
               ' set ', column_name, ' = replace(',column_name,', \‘find this string\’, \‘replace found string with this string\’); ')
FROM information_schema.columns
WHERE table_name = '<TableName>'`
选择CONCAT('updatetable',table_name,
'set',column\u name',=replace(',column\u name','find this string','replace find string with this string\');'))
从信息_schema.columns
其中表_name=“”`

这将为表中的所有列生成update语句(将节省您手动写入列名的时间和精力)。

几乎任何需要对表中所有列重复操作的问题都表明您的架构设计不正确。这些内容不应该有单独的列,而应该是另一个表中与之连接的行,这样您就可以通过一个简单的查询轻松地处理它们。