SQL 重命名表命令
我可以运行 RENAME TABLE Student TO Student_new ;
该命令是相同的并且易于遵循。
有没有一种方法可以用简单的命令重命名很多表。假设所有表都属于同一个数据库名称。
我不需要写很多代码,如下所示?
RENAME TABLE pre_access TO pre_new_access;
RENAME TABLE pre_activities TO pre_new_activities;
RENAME TABLE pre_activityapplies TO pre_new_activityapplies;
RENAME TABLE pre_adminactions TO pre_new_adminactions;
RENAME TABLE pre_admincustom TO pre_new_admincustom;
RENAME TABLE pre_admingroups TO pre_new_admingroups;
RENAME TABLE pre_adminnotes TO pre_new_adminnotes;
...
(还有那么多表需要重命名)
更新:MySQL已使用。
I can run RENAME TABLE student TO student_new
;
The command is same and easy to follow.
Is there a methods to rename a lot of tables in simple command. Assume all the tables belong to the same DB name.
I don't need write a lot of code as below?
RENAME TABLE pre_access TO pre_new_access;
RENAME TABLE pre_activities TO pre_new_activities;
RENAME TABLE pre_activityapplies TO pre_new_activityapplies;
RENAME TABLE pre_adminactions TO pre_new_adminactions;
RENAME TABLE pre_admincustom TO pre_new_admincustom;
RENAME TABLE pre_admingroups TO pre_new_admingroups;
RENAME TABLE pre_adminnotes TO pre_new_adminnotes;
...
(there are still so many tables need to be renamed)
Update: MySQL Used.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据您的评论,假设您使用 MySQL,您应该能够从包含表列表的
information_schema.tables
中“选择”必要的语句。将
your_schema
替换为您的架构名称,并在执行之前检查所选行。回报
Assuming from your comment that you use MySQL, you should be able to "select" the necessary statements from
information_schema.tables
which contains a list of your tables.Replace
your_schema
by your schema-name and check the selected rows before executing them.returns
您始终可以生成一个简单的 PHP 脚本,该脚本循环访问数据库并根据 REGEX 表达式重命名它们。
You could always generate a simple PHP script that loops through the databases and renames them based on a REGEX expression.
您没有提及您正在使用的数据库,这完全依赖于数据库(某些 DBMS 甚至不允许您重命名表)。但是,我不知道有任何 DBMS 系统允许在 RENAME 命令中使用通配符,所以是的,您可能必须单独发送每个命令。
You don't mention what database you're using, and this is completely database dependent (some DBMSes don't even allow you to rename tables). However, I don't know of any DBMS system off the top of my head that allows wildcards in a RENAME command so yes, you will probably have to send each command separately.
对于 mysql 数据库“测试”应该有效:
for mysql database "test" should work: