MySQL查询以查找和替换字段名称中的字符串
是否有mysql查询来查找和替换部分字段名 我知道你可以在实际数据中使用MySQL查询以查找和替换字段名称中的字符串,mysql,replace,Mysql,Replace,是否有mysql查询来查找和替换部分字段名 我知道你可以在实际数据中使用 update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]'); 。。。但是对于实际的字段名,如何做到这一点呢 我有一些字段的名称中有一个-,我想用一个.替换它们。要更改列名,您需要使用ALTER TABLE命令 以下是伪代码的解决方案: Get all table name
update [table_name]
set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
。。。但是对于实际的字段名,如何做到这一点呢
我有一些字段的名称中有一个
-
,我想用一个.
替换它们。要更改列名,您需要使用ALTER TABLE命令
以下是伪代码的解决方案:
Get all table names
Foreach t in table names
Foreach columnname in t containing '-'
newname = old name with "-" replaced with "_"
"ALTER TABLE <tablename> CHANGE <columnname> <newname>"
End
End
获取所有表名
表名中的Foreach t
t中包含“-”的Foreach列名称
newname=旧名称,用“-”替换为“\u1”
“更改表格”
终点
终点