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

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

不知哪里写错了

大家讲道理
大家讲道理

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

reply all(2)
巴扎黑

Underscore is also a wildcard character and should be escaped, otherwise some tables that are not prefixed with 33hao_ will also be included

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

Is the database used wrong? Does the jh database really have the table 33hao_activity?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template