mysql - 这样写替换表前缀的句子哪里有问题
大家讲道理
大家讲道理 2017-04-17 14:56:54
0
2
682

Select CONCAT( 'ALTER TABLE ', table_name, ' RENAME TO jh_', substring(table_name,6 ),';' )FROM information_schema.tables Where table_name LIKE '33hao_%';

想把数据库名为jh中的表前缀为33hao_的换成前缀为jh_

执行上面的代码后ALTER 出很多句子,但在执行这些ALTER句子时出现错误,如下

[SQL]ALTER TABLE 33hao_activity RENAME TO jh__activity;
[Err] 1146 - Table 'jh.33hao_activity' doesn't exist

不知哪里写错了

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

Antworte allen(2)
巴扎黑

下划线也是通配符,应该做escape处理,否则把一些不是前缀为33hao_的表也包含了

select ... from table_name nformation_schema.tables where table_name LIKE '33hao\_%'
PHPzhong

是不是数据库用错了,jh这个数据库真的有33hao_activity这个表嘛?

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!