Mysql 大量刪除首碼或者尾碼表,mysql大量刪除

來源:互聯網
上載者:User

Mysql 大量刪除首碼或者尾碼表,mysql大量刪除

oracl有drop table like 的用法,但是mysql沒有,可以寫指令碼(不做贅述),也可以組裝sql。


注意,我的資料庫名字是test,有個表叫data,然後我準備四個有相同首碼的表,大量刪除,準備資料可以用這條sql

CREATE TABLE test_1201 SELECT * FROM `data`;
CREATE TABLE test_1202 SELECT * FROM `data`;
CREATE TABLE test_1203 SELECT * FROM `data`;
CREATE TABLE test_1205 SELECT * FROM `data`;
SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) AS statement FROM information_schema.tables WHERE table_schema = 'test' AND table_name LIKE 'test_12%';  

上邊這條sql是顯示一個sql結果,把上邊執行出來的結果再執行一邊就可以了。

(只要改table_schema(這是資料庫的名字),跟table_name(這是資料表的名字)即可)
DROP TABLE test_1201,test_1202,test_1203;


mysql 資料庫大量刪除同一首碼的資料表

先建立一個刪除指令碼

運行下語句
select 'drop table '+name from sysobjects where type='U' and name like 'B%'

會出來查詢結果,將查詢結果複製出來
然後在資料庫123中運行複製出來的查詢結果
 
mysql 資料庫SQL語句大量刪除同一首碼的資料表

delete tablename;
或者用用戶端刪除,mysqlfront,phpadmin...
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.