search

Home  >  Q&A  >  body text

mysql - 这样写替换表前缀的句子哪里有问题

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

不知哪里写错了

大家讲道理大家讲道理2868 days ago743

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 14:58:54

    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\_%'

    reply
    0
  • PHPz

    PHPz2017-04-17 14:58:54

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

    reply
    0
  • Cancelreply