How to remove a prefix name from every table name in a mysql database(如何从mysql数据库中的每个表名中删除前缀名)
问题描述
我有一个 joomla mysql 数据库,在我的所有表名上都有一个表名前缀jos_".但我想从我所有的表中删除它.我知道如何重命名每个表,一次一个,但我有 600 个表.是否有一个易于运行的 sql 查询来执行此操作.
I have a joomla mysql database with a table name prefix of "jos_" on all of my table names. But I would like to remove it from all of my tables. I understand how to rename each table, one at a time, but I have 600 tables. Is there an easy to run a sql query to do this.
如果有人有解决方案,能否请您发布我可以使用的确切 sql 查询?
If someone has a solution, could you please post the exact sql query I can use?
推荐答案
您可以使用单个查询生成必要的语句:
You can generate the necessary statements with a single query:
select 'RENAME TABLE ' || table_name || ' TO ' || substr(table_name, 5) ||';'
from information_schema.tables
将该查询的输出保存到一个文件中,您就拥有了所需的所有语句.
Save the output of that query to a file and you have all the statements you need.
或者,如果返回 0s 和 1s 而不是语句,这里是使用 concat 的版本:
Or if that returns 0s and 1s rather the statemenets, here's the version using concat instead:
select concat('RENAME TABLE ', concat(table_name, concat(' TO ', concat(substr(table_name, 5), ';'))))
from information_schema.tables;
这篇关于如何从mysql数据库中的每个表名中删除前缀名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从mysql数据库中的每个表名中删除前缀名
基础教程推荐
- 在 SQL 中连接多个表 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
