将表名重命名为UPPERCASE

时间:2013-05-07 10:19:25

标签: mysql

我在网上找到了几个类似下面的脚本,它们可以预览一旦我解雇脚本后所有的表名都会是这样的:

select concat('RENAME TABLE ', TABLE_NAME, ' TO ', UPPER(TABLE_NAME), ';') from information_schema.TABLES where TABLE_SCHEMA = 'your_db'

但我需要的是一个实际更新数据库中表名的升级脚本,而不仅仅是让我预览名称。

我知道这些伙伴:

lower_case_table_names = 1
lower_case_file_system = 1

但这不是一个选项,因为我无法在我的域上的.ini文件中进行更改 - 所以不必在线重命名每个表我更喜欢重命名(并保存)所有表名的简单脚本马上...... - 这样的更新脚本怎么样......?

2 个答案:

答案 0 :(得分:11)

当托管公司将MySQL数据库从Windows迁移到Linux时,我遇到了类似的问题,必须将所有表名更改为大写:

首先在SQL

phpmyadmin窗口中运行此操作

select concat('rename table ', table_name, ' to ' , upper(table_name) , ';') from information_schema.tables where table_schema = 'your_schema_name';

这将生成一个脚本,该脚本将所有表名称更改为大写,然后将其粘贴到SQL窗口并运行。

答案 1 :(得分:1)

您可能需要考虑以下事项:

   Usage Notes for the INFORMATION_SCHEMA Database
   Although you can select INFORMATION_SCHEMA as the default database with a 
   USE statement,
   you can only read the contents of tables, 
   not perform INSERT, UPDATE, or DELETE operations on them.

链接:http://dev.mysql.com/doc/refman/5.5/en/information-schema.html

以下是另一个解释信息架构问题更新的链接:

mysql root permission to update information_schema error

评论:

https://stackoverflow.com/a/3438369/362574

如何在mysql中实现信息架构表:

https://dba.stackexchange.com/questions/3335/how-is-information-schema-implemented-in-mysql

评论:

https://dba.stackexchange.com/a/3336/12967

相关问题