日常開發或服務器部署時,我們可能會遇到需要清空表或表數據的情況,下面語法執行結果即為清除語句,將結果復制到查詢中執行即可。
table_schema='數據庫名';
1、清空test庫中表數據: select concat('truncate table ',table_schema,'.',table_name,';') as '執行sql' from information_schema.TABLES where table_schema='test'; 2、刪除test庫中所有表: select concat('drop table ',table_schema,'.',table_name,';') as '執行sql' from information_schema.TABLES where table_schema='test';