MySQL批量修改資料庫中的資料表名稱

2021-10-02 21:59:20 字數 3487 閱讀 4950

mysql批量修改資料庫中的資料表名稱

例子:修改資料庫,將shiyong_,修改為think_

select concat(  'alter table ', table_name,  'rename to ', table_name,  ';' ) from information_schema.tables where table_name like  'shiyong_%'
例項:將資料庫qun裡面的表shiyong_,修改為qun_

第一步:

selectconcat( 'altertable',table_name,' rename to ',replace(table_name,'shiyong_','qun_'),';') from information_schema.tables where table_schema = 'qun' andtable_namelike 'shiyong_%';

獲得如下:

altertableshiyong_addresses rename to qun_addresses;

altertableshiyong_admin rename to qun_admin;

altertableshiyong_admin_all rename to qun_admin_all;

altertableshiyong_answer rename to qun_answer;

altertableshiyong_ask rename to qun_ask;

altertableshiyong_bind1 rename to qun_bind1;

altertableshiyong_city rename to qun_city;

altertableshiyong_collection rename to qun_collection;

altertableshiyong_dianpu rename to qun_dianpu;

altertableshiyong_en_home3 rename to qun_en_home3;

altertableshiyong_en_home4 rename to qun_en_home4;

altertableshiyong_en_links rename to qun_en_links;

altertableshiyong_en_list2 rename to qun_en_list2;

altertableshiyong_en_list3 rename to qun_en_list3;

altertableshiyong_en_list4 rename to qun_en_list4;

altertableshiyong_en_list5 rename to qun_en_list5;

altertableshiyong_en_list6 rename to qun_en_list6;

altertableshiyong_en_list7 rename to qun_en_list7;

altertableshiyong_en_tree rename to qun_en_tree;

altertableshiyong_en_trees rename to qun_en_trees;

altertableshiyong_excel2 rename to qun_excel2;

altertableshiyong_home3 rename to qun_home3;

altertableshiyong_jiaoyou rename to qun_jiaoyou;

altertableshiyong_jilu rename to qun_jilu;

altertableshiyong_letters rename to qun_letters;

altertableshiyong_links rename to qun_links;

altertableshiyong_list2 rename to qun_list2;

altertableshiyong_list3 rename to qun_list3;

altertableshiyong_list4 rename to qun_list4;

altertableshiyong_list5 rename to qun_list5;

然後第二步批量執行!

批量修改資料庫中資料

批量修改資料庫中資料 對資料庫中某字段的值增加乙個逗號,如果改值不存在逗號時 update net shop n set n.payment id select case when substr n1.payment id,length n1.payment id 1 then n1.payment...

修改資料 如何批量修改資料庫中的資料

如何在資料庫中動態刪除和建立資料表 第14講 在已有的資料表中刪除 新增 修改欄位的方法 第21講 根據工作表中的資料,生成資料庫中新的資料表的方法 第22講 向乙個已有的資料表中新增資料記錄的方法 第23講 把工作表中提供的資料在資料表中逐一刪除 可以是重複的記錄 的通用方法 第24講 把工作表中...

mysql 修改資料庫

windows環境中 mysql 和php搭配之最佳組合 installdir my.ini 一般在mysql 和php搭配之最佳組合 安裝目錄下有my.ini即mysql 和php搭配之最佳組合 的配置檔案。linux環境中 etc my.cnf 儲存退出編輯。2 然後重啟mysql 和php搭配...