MYSQL批量修改表前缀

发布时间:2021-03-15 编辑:RainNight 阅读:1444

生成相应语句

SELECT
    CONCAT(
        'ALTER TABLE ',
        table_name,
        ' RENAME TO ps_',
        substring(table_name, 8),
        ';'
    )
FROM
    information_schema. TABLES
WHERE
    table_name LIKE 'parking%';

拷贝相应的语句

ALTER TABLE parking_account RENAME TO ps__account;
ALTER TABLE parking_admin RENAME TO ps__admin;
ALTER TABLE parking_admin_role RENAME TO ps__admin_role;
ALTER TABLE parking_city_area RENAME TO ps__city_area;
ALTER TABLE parking_income RENAME TO ps__income;
ALTER TABLE parking_institutional RENAME TO ps__institutional;
ALTER TABLE parking_order RENAME TO ps__order;
ALTER TABLE parking_park_space RENAME TO ps__park_space;
ALTER TABLE parking_rental RENAME TO ps__rental;
ALTER TABLE parking_role RENAME TO ps__role;
ALTER TABLE parking_role_rule RENAME TO ps__role_rule;
ALTER TABLE parking_rule RENAME TO ps__rule;
ALTER TABLE parking_sms RENAME TO ps__sms;
ALTER TABLE parking_toll RENAME TO ps__toll;
ALTER TABLE parking_user RENAME TO ps__user;
ALTER TABLE parking_withdrawal RENAME TO ps__withdrawal;

关键字词[MySQL]